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
i)、###部署deployment.yaml
vi deployment.yaml
######deployment、service
demo.yaml
kubectl apply -f deployment.yaml
##kubectl get pods,service
端口暴露
http://192.168.254.149:30787/
ii)、###升级nginx:1.17 方式一
vi deployment.yaml
image: nginx:1.17 ###1.16--->1.17
kubectl apply -f deployment.yaml
##kubectl get pods,service
http://192.168.254.149:30787/
iii)、###升级过程 查看
kubectl describe deployment web
iiii)、###升级nginx:1.18 方式二 ###1.17--->1.18
#### kubectl set image deployment web <容器名称>=镜像名称
a、####查看容器名称
#spec:
##containers:
## - name: nginx
b、####升级
kubectl set image deployment web nginx=nginx:1.18
http://192.168.254.149:30787/
3)、升级回滚
kubectl rollout history deployment/web ###查看历史发布版本
#### ###1.18--->1.17
kubectl rollout undo deployment/web ###回滚上一个版本
##kubectl get pods,service
http://192.168.254.149:30787/
####kubectl rollout history deployment/web #####
kubectl rollout undo deployment/web --to-revision=2 ###回滚历史指定版本
#### ###1.17--->1.18
vi deployment.yaml
##kubectl apply -f deployment.yaml --record
##kubectl rollout history deployment web
##kubectl get pods,service
kubectl rollout history deployment/web
## ###1.18--->1.19
kubectl set image deployment web nginx=nginx:1.19 --record=true
##kubectl rollout history deployment web
## ###1.18--->1.19
kubectl set image deployment web nginx=nginx:1.19 --record=true
##kubectl rollout history deployment web
## ###1.18--->1.16
kubectl rollout undo deployment/web --to-revision=1
4)、镜像扩/宿容
i)、水平扩####replicas 副本数
a)、####修yaml的repli cas值,再apply -f
## kubectl get pods
##kubectl get pods -w ####实时
vi deployment.yaml
######replicas=6
kubectl apply -f deployment.yaml --record
kubectl get pods -w ####实时
修yaml的repli cas=8值,再apply -f 如下
##kubectl rollout history deployment web###查看历史
b)、#####kubectl scale deployment web --replicas=3
kubectl get pods -w ####实时
5)、镜像下线
a)、#####kubectl delete -f deployment.yaml
####kubectl delete service web
b)、#####kubectl delete deployment web
#####kubectl delete svc/web
注:kubectl delete pod webxxxxxx###deployment会根据replicas值自动恢复
以上是关于Deployment 大全 20220423的主要内容,如果未能解决你的问题,请参考以下文章