编写两个镜像以方便操作
[root@master httpd]# cat Dockerfile
FROM busybox
RUN mkdir /data && \
echo "test page on v1" > /data/index.html
ENTRYPOINT ["/bin/httpd","-f","-h","/data"]
FROM busybox
RUN mkdir /data && \
echo "test page on v2" > /data/index.html
ENTRYPOINT ["/bin/httpd","-f","-h","/data"]
注意:此为测试镜像,只是为展示操作
查看镜像
[root@master httpd]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
dengzichen/httpd v1 37e49703bcb5 4 minutes ago 1.24MB
dengzichen/httpd v2 911a41ce1512 5 minutes ago 1.24MB
busybox latest ffe9d497c324 13 days ago 1.24MB
使用K8s来使用镜像
[root@master ~]# kubectl create deploy httpd --image dengzichen/httpd:v1 --replicas 3
deployment.apps/httpd created
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
httpd-7f6fd56575-g5m5d 1/1 Running 0 36s
httpd-7f6fd56575-t5r2s 1/1 Running 0 36s
httpd-7f6fd56575-xxk8g 1/1 Running 0 36s
[root@master ~]# kubectl expose deploy httpd --port 80 --type NodePort
service/httpd exposed
[root@master ~]# kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
httpd NodePort 10.96.115.185 <none> 80:30296/TCP 9s
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 9h
[root@master ~]# curl http://10.96.115.185
test page on v1
更新
[root@master ~]# kubectl set image deploy/httpd httpd=dengzichen/httpd:v2
deployment.apps/httpd image updated
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
httpd-599c45c854-qzgts 0/1 ContainerCreating 0 3s
httpd-7f6fd56575-g5m5d 1/1 Running 0 16m
httpd-7f6fd56575-t5r2s 1/1 Running 0 16m
httpd-7f6fd56575-xxk8g 1/1 Running 0 16m
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
httpd-599c45c854-7jpcb 1/1 Running 0 3s
httpd-599c45c854-fhpnb 1/1 Running 0 2s
httpd-599c45c854-qzgts 1/1 Running 0 12s
httpd-7f6fd56575-g5m5d 1/1 Terminating 0 16m
httpd-7f6fd56575-t5r2s 1/1 Terminating 0 16m
httpd-7f6fd56575-xxk8g 1/1 Terminating 0 16m
[root@master ~]# curl http://10.96.115.185
test page on v2
回滚
[root@master ~]# kubectl rollout undo deploy/httpd
deployment.apps/httpd rolled back
[root@master ~]# curl http://10.96.115.185
test page on v1
注意:只会回滚到上一个版本,也就是说,你从新版本回滚到旧版本,再回滚则回到新版本,不会往前推。
评论区