1、每个k8s的node节点都需要执行

vi /etc/docker/daemon.json
#输入以下内容,192.168.2.221:80是harbor地址和端口

{ 
"exec-opts": ["native.cgroupdriver=systemd"], 
"registry-mirrors": ["https://hub-mirror.c.163.com","https://registry.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn"],
"insecure-registries":["192.168.2.221:80"]
 }
#让配置生效和重启
systemctl daemon-reload
#重启docker
systemctl restart docker

2、生成认证

#一定要加上端口,不然报错
docker login Harbor的ip和端口 -u admin -p Harbor密码
#生成base64码,该命令获得的参数记录下来
cat ~/.docker/config.json |base64 -w 0

#创建k8s登录认证的凭证
vi registry-pull-secret.yaml
#输入以下内容

apiVersion: v1
kind: Secret
metadata:
  name: registry-pull-secret
data:
#woJImF1dGhzIjogewoJCSIxOTIuMTY4LjIuMjIxOjgwIjogewoJCQkiYXV0aCI6ICJZV1J0YVc0NlNHRnlZbTl5TVRJek5EVT0iCgkJfQoJfQp9这个是上面生成的base64码
 .dockerconfigjson: woJImF1dGhzIjogewoJCSIxOTIuMTY4LjIuMjIxOjgwIjogewoJCQkiYXV0aCI6ICJZV1J0YVc0NlNHRnlZbTl5TVRJek5EVT0iCgkJfQoJfQp9
type: kubernetes.io/dockerconfigjson

3、上传镜像

docker tag myapp/myapp:1.0 ip:端口/libray/myapp:v1
docker push ip:端口/libray/myapp:v1

4、创建应用

vi myapp.yaml
#输入以下内容

apiVersion: apps/v1
kind: Deployment
metadata:
  name: identity
  labels:
    app: identity
spec:
  replicas: 1
  selector:
    matchLabels:
      app: identity
  template:
    metadata:
      labels:
        app: identity
    spec:
      containers:
      #应用名字
      - name: identity
      -#镜像地址
        image: 192.168.2.221:80/center/identity:1.0
      imagePullSecrets:
      #镜像的认证,对应上面创建的registry-pull-secret.yaml的名字
      - name: registry-pull-secre
#创建应用
kubectl apply -f registry-pull-secret.yaml
kubectl apply -f myapp.yaml
Logo

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

更多推荐