在master节点中,通过docker 启动docker 仓库服务:
docker run -d -p 5000:5000 --restart=always --name registry registry:2
没有此镜像会自动下载
更新所有节点的仓库地址
所有的节点都更新/etc/docker/daemon.json,insecure-registries为本地仓库地址。这里我填的本地仓库地址为master节点的ip。
重启所有节点的docker
root@master:/home/tioncico# systemctl daemon-reload root@master:/home/tioncico# systemctl restart docker
打包镜像推送到本地节点
docker tag tioncico/go:v1.0.1 192.168.192.9:5000/tioncico/go:v1.0.1 //原有教程有build,这里直接打一个新的tag docker push 192.168.192.9:5000/tioncico/go:v1.0.1
部署go的yaml文件修改
主要是指定image的地址:
\-\-\- apiVersion: apps/v1 kind: Deployment metadata: name: go-deployment labels: app: go spec: selector: matchLabels: app: go replicas: 3 minReadySeconds: 5 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 1 template: metadata: labels: app: go spec: containers: - image: 192.168.192.9:5000/tioncico/go:v1.0.1 name: go imagePullPolicy: Always command: \["./main","-v","v1.0.1"\] ports: - containerPort: 8080 protocol: TCP \-\-\- apiVersion: v1 kind: Service metadata: name: go-service labels: app: go spec: selector: app: go ports: - name: go-port protocol: TCP port: 8080 targetPort: 8080 nodePort: 30080 type: NodePort
然后部署即可