Deployment 大全 20220423

Posted cn2021

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Deployment 大全 20220423相关的知识,希望对你有一定的参考价值。

deployment 大全

1)、部署

kubel apply -f xxx.yaml

apiVersion: apps/v1

kind: Deployment

metadata:

name: web

### namespace : default

spec:

replicas: 3 #pod副本数量

selector:

matchLabels:

app: nginx

template:nginx

metadata:

labels:

app: web #pod副本标签

spec:

containers:

- name: nginx

image: nginx:1.16

ports:

- containerPort: 80

2)、镜像升级

####滚动升级################1.16 -->1.17 --> 1.18

###kubel set image deployment/web nginx=nginx:1.17


###kubectl get pods

###kubectl delete deployment web

###kubectl get services

###kubectl delete service web

###kubectl get pods,service

Deployment


 Deployment


 Deployment

 i)、###部署deployment.yaml

vi deployment.yaml

Deployment

######deployment、service

demo.yaml

Deployment

kubectl apply -f  deployment.yaml

##kubectl get pods,service

Deployment

端口暴露

 Deployment

Deployment

http://192.168.254.149:30787/

                   ii)、###升级nginx:1.17      方式一

vi deployment.yaml

Deployment

image: nginx:1.17 ###1.16--->1.17

kubectl apply -f deployment.yaml

Deployment



##kubectl get pods,service

Deployment

http://192.168.254.149:30787/

iii)、###升级过程 查看

kubectl describe deployment web

Deployment

    iiii)、###升级nginx:1.18 方式二 ###1.17--->1.18

                                     #### kubectl   set image       deployment    web   <容器名称>=镜像名称 

        a、####查看容器名称

        #spec:

        ##containers:

        ## - name: nginx

                                  Deployment


                        b、####升级

                       kubectl set image       deployment    web       nginx=nginx:1.18

 Deployment

 http://192.168.254.149:30787/


Deployment

3)、升级回滚

kubectl rollout history deployment/web ###查看历史发布版本

Deployment


#### ###1.18--->1.17

kubectl rollout undo deployment/web ###回滚上一个版本

##kubectl get pods,service

Deployment

http://192.168.254.149:30787/

 Deployment


####kubectl rollout history deployment/web #####

kubectl rollout undo deployment/web --to-revision=2 ###回滚历史指定版本

#### ###1.17--->1.18

vi deployment.yaml

Deployment


Deployment

##kubectl apply -f deployment.yaml --record

##kubectl rollout history deployment web

Deployment


 Deployment


##kubectl get pods,service

Deployment


kubectl rollout history deployment/web 

Deployment


## ###1.18--->1.19

kubectl set image deployment web nginx=nginx:1.19 --record=true

##kubectl rollout history deployment web

Deployment


## ###1.18--->1.19

kubectl set image deployment web nginx=nginx:1.19 --record=true

##kubectl rollout history deployment web

Deployment

## ###1.18--->1.16

kubectl rollout undo deployment/web --to-revision=1

 Deployment

 Deployment


4)、镜像扩/宿容

i)、水平扩####replicas 副本数


        a)、####修yaml的repli cas值,再apply -f

## kubectl get pods

##kubectl get pods -w ####实时

Deployment

vi deployment.yaml

######replicas=6

Deployment

kubectl apply -f deployment.yaml --record

kubectl   get pods -w  ####实时

Deployment


 Deployment

 Deployment

修yaml的repli cas=8值,再apply -f   如下

Deployment

##kubectl rollout history  deployment   web###查看历史

 Deployment

          b)、#####kubectl scale deployment web --replicas=3

Deployment

 kubectl   get pods -w  ####实时

Deployment

5)、镜像下线

                                                a)、#####kubectl delete -f deployment.yaml

####kubectl delete service web


Deployment

b)、#####kubectl delete deployment web

#####kubectl delete svc/web

注:kubectl  delete  pod   webxxxxxx###deployment会根据replicas值自动恢复


以上是关于Deployment 大全 20220423的主要内容,如果未能解决你的问题,请参考以下文章

MDT (Microsoft Deployment Toolkit) 的功能大全,包括其主要部分和功能

K8S的各种资源使用技巧

K8SRCRS和Deployment

k8s-deployment

K8SRCRS和Deployment

K8SRCRS和Deployment