Kubernates之如何从Harbor上拉去镜像创建服务
本文主要介绍"Kubernates之怎么从Harbor上拉去镜像创建服务",希望能够解决您遇到有关问题,下面我们一起来看这篇 "Kubernates之怎么从Harbor上拉去镜像创建服务" 文章。
1、将Harbor加入k8s宿主机Docker的insecure-registries中
修改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
2、用yaml在k8s上创建服务
在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上拉去镜像创建服务" 就介绍到这。希望大家多多支持编程宝库。
Flutter用户侧问题怎么解决:本文主要介绍"Flutter用户侧问题如何解决",希望能够解决您遇到有关问题,下面我们一起来看这篇 "Flutter用户侧问题如何解决" 文章。背景现在的app基本都会提供用户反馈问题的入口,然而提供给用户 ...