这篇文章将为大家详细讲解有关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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。