Kubernetes Harbor等资源--secret和ServiceAccount配置
![]
来啦,老弟
##########
用途
secret对象类型主要目的是保存和处理敏感信息/私密数据。将这些信息放在secret对象中比 直接放在pod或docker image中更安全,也更方便使用。在一个已经创建好的secrets对象有两种方式被pod对象使用,其一,在container中的volume对象里以file的形式被使用,其二,在pull images时被kubelet使用。
####
####
####
####
实操
(1)
执行login命令,登录私有Registry
[[email protected] source]#docker login -u admin -p Harbor repository.xxxx.com (输入账户及密码,如果是第1次登录则会创建新用户,并把相关信息写入~/.docker/config.json?文件中)
#####
#####
(2)
用BASE64编码dockercfg的内容
[[email protected] source]# cat /root/.docker/config.json | base64 -w 0
ewoJImF1dGhzIjogewoJCSJiYXNpYy1yZXBvc2l0b3J5LnNrb25nLmNvbSI6IHsKCQkJImF1dGgiOiAiWVdSdGFXNDZTR0Z5WW05eU1USXpORFUyIgoJCX0sCgkJInJlcG9zaXRvcnkuc2tvbmcuY29tIjogewoJCQkiYXV0aCI6ICJZV1J0YVc0NlNHRnlZbTl5TVRJek5EVTIiCgkJfQoJfQp9
(-w 0 是输出一行的意思)
#####
#####
(3)
将上一步命令的输出结果作为Secret的“data.dockercfg”域的内容,由此来创建一个Secret。我试验不好用,之后我该用:
1.
[[email protected] images_cert]# cat secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: kubesystemsecret
namespace: default
data:
.dockerconfigjson: ewoJImF1dGhzIjogewoJCSJiYXNpYy1yZXBvc2l0b3J5LnNrb25nLmNvbSI6IHsKCQkJImF1dGgiOiAiWVdSdGFXNDZTR0Z5WW05eU1USXpORFUyIgoJCX0sCgkJInJlcG9zaXRvcnkuc2tvbmcuY29tIjogewoJCQkiYXV0aCI6ICJZV1J0YVc0NlNHRnlZbTl5TVRJek5EVTIiCgkJfQoJfQp9
type: kubernetes.io/dockerconfigjson
#####
#####
2、
[[email protected] source]#kubectl create secret basic-repository secret-name --namespace=default --docker-server=https://basic-repository.skong.com --docker-username=admin --docker-password=Harbor [email protected] (本身就可以使用)
#####
#####
3、
[[email protected] templet]# cat templet.yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: projectname-environment-deployment
spec:
replicas: 2
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
template:
metadata:
labels:
app: projectname-environment-pod
spec:
terminationGracePeriodSeconds: 60
containers:
- name: projectname-environment-pod
image: basic-repository.skong.com/skong/projectname-environment:branch
ports:- containerPort: 80
imagePullSecrets:
- containerPort: 80
- name: kubesystemsecret
apiVersion: v1
kind: Service
metadata:
name: projectname-environment-service
labels:
app: projectname-environment-service
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
app: projectname-environment-pod
#####
#####
点一下动图
原文地址:http://blog.51cto.com/13386520/2329611