1. 程式人生 > >Kubernetes Harbor等資源--secret和ServiceAccount配置

Kubernetes Harbor等資源--secret和ServiceAccount配置

Kubernetes Harbor等資源--secret和ServiceAccount配置

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:
  • 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

#####
Kubernetes Harbor等資源--secret和ServiceAccount配置

#####

Kubernetes Harbor等資源--secret和ServiceAccount配置

點一下動圖