1.Harbor

此处省略Harbor的安装部署

在这里插入图片描述

2.修改配置文件

PS:修改K8s集群中的docker配置文件节点也需要修改。

[root@master ~]# vim /usr/lib/systemd/system/docker.service 
#查找这一行 并删除更改为带IP的哪一行
ExecStart=/usr/bin/dockerd -H unix://

ExecStart=/usr/bin/dockerd --insecure-registry 192.168.1.43
[root@master ~]# systemctl  daemon-reload 
[root@master ~]# systemctl  restart docker

3.登录Harbor仓库

[root@master ~]# docker login -u admin -p Harbor12345  192.168.1.43
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

4.查看登录密钥数据

[root@master ~]# cat .docker/config.json 
{
	"auths": {
		"192.168.1.43": {
			"auth": "YWRtaW46SGFyYm9yMTIzNDU="
		}
	},
	"HttpHeaders": {
		"User-Agent": "Docker-Client/18.09.0 (linux)"
	}

5.进行base加密

[root@master ~]# cat .docker/config.json  | base64
ewoJImF1dGhzIjogewoJCSIxOTIuMTY4LjEuNDMiOiB7CgkJCSJhdXRoIjogIllXUnRhVzQ2U0dG
eVltOXlNVEl6TkRVPSIKCQl9Cgl9LAoJIkh0dHBIZWFkZXJzIjogewoJCSJVc2VyLUFnZW50Ijog
IkRvY2tlci1DbGllbnQvMTguMDkuMCAobGludXgpIgoJfQp9

6.创建Secret资源

[root@master ~]#  vim secret.yaml 
apiVersion: v1
kind: Secret
metadata:
  name: registry-secret
type: kubernetes.io/dockerconfigjson
data:
  .dockerconfigjson:  ewoJImF1dGhzIjogewoJCSIxOTIuMTY4LjEuNDMiOiB7CgkJCSJhdXRoIjogIllXUnRhVzQ2U0dGeVltOXlNVEl6TkRVPSIKCQl9Cgl9LAoJIkh0dHBIZWFkZXJzIjogewoJCSJVc2VyLUFnZW50IjogIkRvY2tlci1DbGllbnQvMTguMDkuMCAobGludXgpIgoJfQp9
  
[root@master ~]# kubectl apply -f secret.yaml
secret/registry-secret created

7.创建Deployment资源引用secret资源

[root@master ~]# vim deployment.yaml

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: web
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: web
    spec:
      imagePullSecrets:
      - name: harbor-secret
      containers:
      - name: web
        image: 192.168.1.43/web/httpd:v1

[root@master ~]# kubectl  apply  -f deployment.yaml 
deployment.extensions/web created

查看结果

[root@master ~]# kubectl  get pod -o wide | grep web
web-599fb688c6-4jcqm      1/1     Running   0          81s    10.244.1.16   node02   <none>           <none>
web-599fb688c6-q8blc      1/1     Running   0          81s    10.244.2.18   node01   <none>           <none>
[root@master ~]# curl  10.244.1.16
111
[root@master ~]# curl  10.244.2.18
111
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐