美文网首页
Deployment 部署

Deployment 部署

作者: 懒猫睡醒了 | 来源:发表于2022-05-19 08:25 被阅读0次

    运行Deployment

    步骤
    1.创建一个Deployment

    root@k8s-master:~# kubectl create deployment maydep --image=httpd:2.2
    deployment.apps/maydep created

    2.查看Deployment

    root@k8s-master:~# kubectl get deployment
    NAME READY UP-TO-DATE AVAILABLE AGE
    maydep 1/1 1 1 41s

    3.弹性扩展

    root@k8s-master:~# kubectl scale deployment maydep --replicas=3
    deployment.apps/maydep scaled
    root@k8s-master:~# kubectl get pod
    NAME READY STATUS RESTARTS AGE
    maydep-54c745d8db-dl4kc 1/1 Running 0 11s
    maydep-54c745d8db-jrt7f 1/1 Running 0 101s
    maydep-54c745d8db-q85z6 1/1 Running 0 11s

    4.查看pod IP地址列表

    root@k8s-master:~# kubectl get pods -l app=mynginx -o go-template='{{range .items}}{{.status.podIP}}{{"\n"}}{{end}}'
    192.168.169.155
    192.168.36.87
    192.168.169.154
    192.168.169.151
    192.168.36.83

    修改Deployment,实现版本升级

    步骤
    1.edit deployment

    root@k8s-master:~# kubectl edit deployment maydep


    image.png

    2.查看deployment

    root@k8s-master:~# kubectl get deployment -o wide
    NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
    maydep 3/3 3 3 4m54s httpd httpd:2.4 app=maydep

    3.查看deployment更新事件信息

    root@k8s-master:~# kubectl describe deployment maydep


    image.png

    4.查看deployment 更新记录

    root@k8s-master:~# kubectl rollout history deployment maydep

    deployment.apps/maydep
    REVISION CHANGE-CAUSE
    1 <none>
    2 <none>

    5.查看历史版本1或2的信息

    root@k8s-master:~# kubectl rollout history deployment maydep --revision=1
    deployment.apps/maydep with revision #1
    Pod Template:
    Labels: app=maydep
    pod-template-hash=54c745d8db
    Containers:
    httpd:
    Image: httpd:2.2
    Port: <none>
    Host Port: <none>
    Environment: <none>
    Mounts: <none>
    Volumes: <none>

    root@k8s-master:~# kubectl rollout history deployment maydep --revision=2
    deployment.apps/maydep with revision #2
    Pod Template:
    Labels: app=maydep
    pod-template-hash=7585487c48
    Containers:
    httpd:
    Image: httpd:2.4
    Port: <none>
    Host Port: <none>
    Environment: <none>
    Mounts: <none>
    Volumes: <none>

    6.回滚到之前的历史版本1

    root@k8s-master:~# kubectl rollout undo deployment maydep --to-revision=1
    deployment.apps/maydep rolled back

    7.查看当前的历史版本

    root@k8s-master:~# kubectl get deployment -o wide
    NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
    maydep 3/3 3 3 19m httpd httpd:2.2 app=maydep

    8.删除deployment

    root@k8s-master:~# k delete deployment mydep
    deployment.apps "mydep" deleted

    相关文章

      网友评论

          本文标题:Deployment 部署

          本文链接:https://www.haomeiwen.com/subject/jaxaurtx.html