您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關Kubernates之如何從Harbor上拉去鏡像創建服務,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
修改k8s的master和倆個node的/etc/docker/daemon.json,將192.168.33.5將入到insecure-registries中,如下所示:
List-1.1
[root@localhost data]# more /etc/docker/daemon.json {"bip": "172.172.172.1/24","insecure-registries": ["10.221.128.52","192.168.33.5"]}
重啟Docker服務,如下List-1.2
List-1.2
[root@localhost data]# systemctl daemon-reload [root@localhost data]# systemctl restart Docker
在每個節點上試試能否login到192.168.33.5,如下List-1.3
List-1.3
[root@localhost data]# docker login 192.168.33.5 Username (mjduan): Password: Login Succeeded
在master節點執行如下List-2.1,創建secret,其中registry-harbor2是名稱,namespace的值使用default,docker-server的值是Harbor的IP,docker-username和docker-password的值是在Harbor上創建的用戶。
List-2.1
kubectl create secret docker-registry registry-harbor2 --namespace=default \ --docker-server=http://192.168.33.5 --docker-username=mjduan \ --docker-password=***** --docker-email=dmj1161859184@126.com
List-2.2 查看創建了的secret
[root@localhost data]# kubectl get secret NAME TYPE DATA AGE default-token-dqvqc kubernetes.io/service-account-token 3 12h registry-harbor2 kubernetes.io/dockerconfigjson 1 5h
創建如下List-2.3所示的nginx.yaml,注意imagePullSecrets的值是registry-harbor2
List-2.3
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx template: metadata: labels: app: nginx spec: containers: - name: nginx image: 192.168.33.5/project/nginx:1.0 imagePullPolicy: Always ports: - containerPort: 80 imagePullSecrets: - name: registry-harbor2 --- apiVersion: v1 kind: Service metadata: name: nginx-service spec: type: NodePort sessionAffinity: ClientIP selector: app: nginx ports: - port: 80 nodePort: 30180
之后用kubectl創建服務,如下List-2.4
List-2.4
[root@localhost data]# create -f deploy-nginx.yaml
查看結果,如下List-2.5
List-2.5
[root@localhost data]# kubectl get services NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 12h nginx-service NodePort 10.103.100.169 <none> 80:30180/TCP 5h [root@localhost data]# kubectl get pods NAME READY STATUS RESTARTS AGE nginx-deployment-789794d957-m7wjv 1/1 Running 0 5h [root@localhost data]#
關于“Kubernates之如何從Harbor上拉去鏡像創建服務”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。