kubectl子命令使用分类
1.(基础命令)
(2)部署和集群管理命令
(3)故障调试命令
(4)其他命令
[root@master ~]# kubectl get cs #查看当前状态
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME STATUS MESSAGE ERROR
scheduler Unhealthy Get "http://127.0.0.1:10251/healthz": dial tcp 127.0.0.1:10251: connect: connection refused
controller-manager Unhealthy Get "http://127.0.0.1:10252/healthz": dial tcp 127.0.0.1:10252: connect: connection refused
etcd-0 Healthy {"health":"true"} #状态检查发现是unhealth,解决办法:注释掉下面两个文件夹的--port=0
[root@master ~]# vim /etc/kubernetes/manifests/kube-controller-manager.yaml
[root@master ~]# vim /etc/kubernetes/manifests/kube-scheduler.yaml
#再次检查,变成health了。
[root@master ~]# kubectl get cs
Warning: v1 ComponentStatus is deprecated in v1.19+
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy {"health":"true"}
[root@master ~]#
Kubernetes 集群YAML文件详解
1.YAML文件概述
k8s集群中对资源管理和资源对象编排部署都可以通过声明样式(YAML)文件来解决,也就是说可以把需要对资源对象操作编辑到YAML格式文件中,我们把这种文件叫做资源清单文件,通过kubectl 命令直接使用资源清单文件就可以实现对大量的资源对象进行编排部署了。
2.YAML文件书写格式
(1)YAML介绍
YAML:仍是一种标记语言。为了强调这种语言以数据作为中心,而不是以标记语言为重点。
YAML是一个可读性高,用来表达数据序列的格式。
(2)YAML基本语法
使用空格作为缩进
缩进的空格数目不重要,只要相同层级的元素左侧对齐即可。
语法格式:
-
通过缩进表示层级关系
-
不能使用Tab进行缩进,只能使用空格
-
一般开头缩进两个空格
-
字符后缩进一个空格,比如冒号,逗号等后面缩进一个空格。
-
使用---表示新的yaml文件开始
-
使用#代表注释
yaml文件组成部分
(1)控制器定义
如何快速编写yaml文件
第一种使用kubectl create命令生成yaml文件
[root@master ~]# kubectl create deployment web --image=nginx -o yaml --dry-run
W0608 16:42:14.284905 10172 helpers.go:553] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web
name: web
spec:
replicas: 1
selector:
matchLabels:
app: web
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
[root@master ~]# kubectl create deployment web --image=nginx -o yaml --dry-run > my1.yaml
W0608 16:42:56.667661 10462 helpers.go:553] --dry-run is deprecated and can be replaced with --dry-run=client.
[root@master ~]# ls
10-flannel.conflist admin.conf deploy.yaml.1 kube-flannel.yml recommended.yaml
10-kubeadm.conf deploy.yaml ingress-nginx-rule.yaml my1.yaml
[root@master ~]# cat my1.yaml
第二种方式 当资源已经部署了,从部署资源中,拿出来已经生成好的yaml文件对它做修改。使用kubectl get 命令导出yaml文件。
[root@master ~]# kubectl get deploy
NAME READY UP-TO-DATE AVAILABLE AGE
nginx 1/1 1 1 45h
tomcat 1/1 1 1 44h
[root@master ~]# kubectl get deployment nginx -o=yaml --export > my2.yaml
Error: unknown flag: --export
See 'kubectl get --help' for usage.
#原因是 --export在所使用的版本中已经被去除了,将--export删除即可,改成:
[root@master ~]# kubectl get deployment nginx -o=yaml > my2.yaml
[root@master ~]# ls
10-flannel.conflist admin.conf deploy.yaml.1 kube-flannel.yml my2.yaml
10-kubeadm.conf deploy.yaml ingress-nginx-rule.yaml my1.yaml recommended.yaml
[root@master ~]#
kubernetes核心技术-Pod
1.Pod概述
Pod 是 k8s 系统中可以创建和管理的最小单元,是资源对象模型中由用户创建或部署的最小资源对象模型,也是在 k8s 上运行容器化应用的资源对象,其他的资源对象都是用来支撑或者扩展 Pod 对象功能的,比如控制器对象是用来管控 Pod 对象的,Service 或者 Ingress 资源对象是用来暴露 Pod 引用对象的,PersistentVolume 资源对象是用来为 Pod提供存储等等,k8s 不会直接处理容器,而是 Pod,Pod 是由一个或多个 container 组成Pod 是 Kubernetes 的最重要概念,每一个 Pod 都有一个特殊的被称为”根容器“的 Pause 容器。Pause 容器对应的镜 像属于 Kubernetes 平台的一部分,除了 Pause 容器,每个 Pod还包含一个或多个紧密相关的用户业务容器
(1)最小部署的单元
(2)包含多个容器(一组容器的集合)
(3)一个pod中容器共享网络命令空间
(4)pod是短暂的
2.Pod存在的意义
(1)创建容器使用docker(单进程),一个docker对应一个容器,一个容器有一个进程,一个容器运行一个应用程序。
(2)Pod是多进程设计,运行多个应用程序
-
一个Pod有多个容器,一个容器里面运行一个应用程序
(3)Pod存在为了亲密性应用
-
两个应用之间进行交互
-
网络之间调用
-
两个应用需要频繁调用
3.Pod实现机制
(1)共享网络:通过Pause容器,把其他业务容器加入到pause容器里面,让所有业务容器在同一个名称空间中,可以实现网络共享。
(2)共享存储:引入数据卷概念Volumn,把其他业务容器加入到Pause容器里面,让所有容器在同一个名称空间中,可以实现网络共享。
4.Pod镜像拉取策略
5.Pod资源限制示例
6.Pod重启机制
7.Pod健康检查
[root@master ~]# touch /tmp/a
[root@master ~]# cat /tmp/a
[root@master ~]# echo $?
0
[root@master ~]# rm /tmp/a
rm: remove regular empty file ‘/tmp/a’? y
[root@master ~]# echo $? #查看状态码
0
[root@master ~]# cat /tmp/a
cat: /tmp/a: No such file or directory
[root@master ~]# echo $?
1
8.Pod调度
影响调用的属性
-
Pod资源限制对Pod调用产生影响
根据request找到足够node节点进行调度
-
节点选择器标签影响Pod调度
首先对节点创建标签
#例如:
kubectl label node node1 env_role=prod
[root@master ~]# kubectl label node node01 env_role=dev
node/node01 labeled
[root@master ~]# kubectl get nodes node01 --show-labels
NAME STATUS ROLES AGE VERSION LABELS
node01 Ready <none> 2d22h v1.20.7 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,env_role=dev,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux
9.节点亲和性
支持常用操作符:
In NotIn Exists Gt Lt DoesNotExists
10.影响Pod调度
污点和污点容忍
(1)基本介绍:nodeSelector和nodeAffinity: Pod调度到某些节点上,Pod属性,调度时候实现
Taint污点:节点不做普通分配调度,是节点属性
(2)场景
-
专用节点
-
配置特定硬件节点
-
基于Taint驱逐
(3)具体演示
#查看节点污点情况
[root@master ~]# kubectl describe node master | grep Taint
Taints: node-role.kubernetes.io/master:NoSchedule
[root@master ~]#
污点值有三个
-
NoSchedule:一定不被调度
-
PreferNoSchdule:尽量不被调度
-
NoExecute:不会被调度,并且还会驱逐Node已有Pod
(4)为节点添加污点
kubectl taint node [node] key=value:污点三个值
[root@master ~]# kubectl describe node master | grep Taint
Taints: node-role.kubernetes.io/master:NoSchedule
[root@master ~]# kubectl describe node node01 | grep Taint
Taints: <none>
[root@master ~]# kubectl describe node node02 | grep Taint
Taints: <none>
[root@master ~]# kubectl describe node node03 | grep Taint
Taints: <none>
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d
[root@master ~]# kubectl create deployment web --image=nginx
deployment.apps/web created
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d
web-96d5df5c8-6hq2l 0/1 ContainerCreating 0 14s
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d
web-96d5df5c8-6hq2l 1/1 Running 0 26s
#查看被分配到的节点
[root@master ~]# kubectl get pods -o wide #查看被分配到的节点
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d 10.244.2.6 node02 <none> <none>
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d 10.244.1.6 node01 <none> <none>
web-96d5df5c8-6hq2l 1/1 Running 0 50s 10.244.1.11 node01 <none> <none>副本
[root@master ~]# kubectl scale deployment web --replicas=5 #创建
deployment.apps/web scaled
[root@master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d 10.244.2.6 node02 <none> <none>
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d 10.244.1.6 node01 <none> <none>
web-96d5df5c8-6hq2l 1/1 Running 0 4m19s 10.244.1.11 node01 <none> <none>
web-96d5df5c8-bktth 0/1 ContainerCreating 0 13s <none> node01 <none> <none>
web-96d5df5c8-cshfg 0/1 ContainerCreating 0 13s <none> node02 <none> <none>
web-96d5df5c8-nbtdr 0/1 ContainerCreating 0 13s <none> node01 <none> <none>
web-96d5df5c8-nlblr 0/1 ContainerCreating 0 13s <none> node02 <none> <none>
[root@master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d 10.244.2.6 node02 <none> <none>
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d 10.244.1.6 node01 <none> <none>
web-96d5df5c8-6hq2l 1/1 Running 0 6m20s 10.244.1.11 node01 <none> <none>
web-96d5df5c8-bktth 1/1 Running 0 2m14s 10.244.1.13 node01 <none> <none>
web-96d5df5c8-cshfg 1/1 Running 0 2m14s 10.244.2.11 node02 <none> <none>
web-96d5df5c8-nbtdr 1/1 Running 0 2m14s 10.244.1.12 node01 <none> <none>
web-96d5df5c8-nlblr 1/1 Running 0 2m14s 10.244.2.12 node02 <none> <none>
[root@master ~]# kubectl delete deployment web #删除web
deployment.apps "web" deleted
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d
# 创建污点 env_role是创建的名字
[root@master ~]# kubectl taint node node01 env_role=yes:NoSchedule #为node01加上污点
node/node01 tainted
[root@master ~]# kubectl create deployment web --image=nginx
deployment.apps/web created
[root@master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d1h 10.244.2.6 node02 <none> <none>
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d 10.244.1.6 node01 <none> <none>
web-96d5df5c8-4sj5m 1/1 Running 0 25s 10.244.2.13 node02 <none> <none>
[root@master ~]# kubectl scale deployment web --replicas=5
deployment.apps/web scaled
[root@master ~]# kubectl get pods -o wide #因为node01设置了污点所以创建的五个web调度不到
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d1h 10.244.2.6 node02 <none> <none>
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d 10.244.1.6 node01 <none> <none>
web-96d5df5c8-4sj5m 1/1 Running 0 94s 10.244.2.13 node02 <none> <none>
web-96d5df5c8-mdqrb 0/1 ContainerCreating 0 23s <none> node02 <none> <none>
web-96d5df5c8-nxppp 0/1 ContainerCreating 0 23s <none> node03 <none> <none>
web-96d5df5c8-tk2cd 0/1 ContainerCreating 0 23s <none> node02 <none> <none>
web-96d5df5c8-wlnn7 0/1 ContainerCreating 0 23s <none> node02 <none> <none>
[root@master ~]# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d1h 10.244.2.6 node02 <none> <none>
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d 10.244.1.6 node01 <none> <none>
web-96d5df5c8-4sj5m 1/1 Running 0 4m3s 10.244.2.13 node02 <none> <none>
web-96d5df5c8-mdqrb 1/1 Running 0 2m52s 10.244.2.15 node02 <none> <none>
web-96d5df5c8-nxppp 1/1 Running 0 2m52s 10.244.3.11 node03 <none> <none>
web-96d5df5c8-tk2cd 1/1 Running 0 2m52s 10.244.2.16 node02 <none> <none>
web-96d5df5c8-wlnn7 1/1 Running 0 2m52s 10.244.2.14 node02 <none> <none>
#删除污点 env_role是创建的名字
[root@master ~]# kubectl describe node node01 | grep Taint
Taints: env_role=yes:NoSchedule
[root@master ~]# kubectl taint node node01 env_role:NoSchedule- #删除污点
node/node01 untainted
[root@master ~]# kubectl describe node node01 | grep Taint
Taints: <none>
11.污点容忍
Controller
1.什么是Controller
-
确保预期的pod副本数量
-
无状态应用部署
-
有状态应用部署
-
在集群上管理和运行容器的对象
确保所有的node运行同一个pod
一次性任务和定时任务
2.Pod和Controller关系
-
Pod是通过Controller实现应用的运维,比如伸缩,滚动升级等
-
Pod和Controller之间通过label标签建立关系 selector
3.deployment应用场景
-
部署无状态应用
-
管理Pod和ReplicaSet
-
部署,滚动升级等功能
应用场景:web服务,微服务
4.使用deployment部署应用(yaml)
第一步#生成yaml文件
[root@master ~]# kubectl create deployment web --image=nginx --dry-run -o yaml
W0608 21:03:20.882677 24381 helpers.go:553] --dry-run is deprecated and can be replaced with --dry-run=client.
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web
name: web
spec:
replicas: 1
selector: #控制器里面的selector标签
matchLabels:
app: web
strategy: {}
template: #template模板里面是pod
metadata:
creationTimestamp: null
labels:
app: web
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
第二步#导出yaml文件
[root@master ~]# kubectl create deployment web --image=nginx --dry-run=client -o yaml > web.yaml
[root@master ~]# ls
10-flannel.conflist admin.conf deploy.yaml.1 kube-flannel.yml my2.yaml web.yaml
10-kubeadm.conf deploy.yaml ingress-nginx-rule.yaml my1.yaml recommended.yaml
#删除yaml文件
[root@master ~]# rm my1.yaml
rm: remove regular file ‘my1.yaml’? y
[root@master ~]# rm my2.yaml
rm: remove regular file ‘my2.yaml’? y
[root@master ~]# cat web.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web
name: web
spec:
replicas: 1
selector:
matchLabels:
app: web
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web
spec:
containers:
- image: nginx
name: nginx
resources: {}
status: {}
[root@master ~]#
第三步#使用yaml文件部署应用
[root@master ~]# kubectl apply -f web.yaml
Warning: resource deployments/web is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
deployment.apps/web configured
[root@master ~]# ls
10-flannel.conflist admin.conf deploy.yaml.1 kube-flannel.yml web.yaml
10-kubeadm.conf deploy.yaml ingress-nginx-rule.yaml recommended.yaml
[root@master ~]# kubectl get pods #查看状态
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d1h
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d1h
web-96d5df5c8-nxppp 1/1 Running 0 37m
[root@master ~]#
第四步#对外发布(暴露对外端口号)
[root@master ~]# kubectl expose deployment web --port=80 --type=NodePort --target-port=80 --name=web1 -o yaml > web1.yaml
[root@master ~]# ls
10-flannel.conflist admin.conf deploy.yaml.1 kube-flannel.yml web1.yaml
10-kubeadm.conf deploy.yaml ingress-nginx-rule.yaml recommended.yaml web.yaml
[root@master ~]# cat web1.yaml #查看这个文件
[root@master ~]# kubectl apply -f web1.yaml #应用这个文件
Warning: resource services/web1 is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
service/web1 configured
[root@master ~]# kubectl get pods,svc #查看对外端口号
NAME READY STATUS RESTARTS AGE
pod/nginx-6799fc88d8-kqfmm 1/1 Running 3 2d1h
pod/tomcat-7d987c7694-8sjkd 1/1 Running 2 2d1h
pod/web-96d5df5c8-nxppp 1/1 Running 0 54m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 3d
service/nginx NodePort 10.98.160.67 <none> 80:32169/TCP 2d1h
service/tomcat NodePort 10.105.92.64 <none> 8080:30513/TCP 2d1h
service/web1 NodePort 10.111.154.60 <none> 80:32594/TCP 2m15s
[root@master ~]#
注意:master或者node的阿里云Ip加上这个端口号都可以访问到nginx界面,32594这个端口号要在阿里云安全组进行配置
5.应用升级回滚和弹性伸缩
[root@master ~]# vim web.yaml
[root@master ~]# cat web.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: web
name: web
spec:
replicas: 2
selector:
matchLabels:
app: web
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: web
spec:
containers:
- image: nginx:1.14
name: nginx
resources: {}
status: {}
[root@master ~]# kubectl apply -f web.yaml
deployment.apps/web configured
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d2h
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d1h
web-88c6cbf44-2mz4b 1/1 Running 0 85s
web-88c6cbf44-8gnkb 1/1 Running 0 5m22s
#把nginx1.14版本升级到1.15版本
[root@master ~]# kubectl set image deployment web nginx=nginx:1.15
deployment.apps/web image updated
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d2h
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d1h
web-586db47859-px6r4 1/1 Running 0 62s#这个1.14版本的没有停住,继续启用
web-586db47859-zgw49 1/1 Running 0 36s#这个1.14版本的没有停住。继续启用
web-88c6cbf44-2mz4b 0/1 Terminating 0 4m27s# 这个过程在下载1.15的镜像
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d2h
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d1h
web-586db47859-px6r4 1/1 Running 0 101s#1.15替换掉了1.14
web-586db47859-zgw49 1/1 Running 0 75s#1.15替换掉了1.14
#查看升级的状态
[root@master ~]# kubectl rollout status deployment web
deployment "web" successfully rolled out
#查看升级版本
[root@master ~]# kubectl rollout history deployment web
deployment.apps/web
REVISION CHANGE-CAUSE #这里有3个版本
1 <none>
2 <none>
3 <none>
#回滚到上一个版本
[root@master ~]# kubectl rollout undo deployment web
deployment.apps/web rolled back
[root@master ~]# kubectl rollout status deployment web
Waiting for deployment "web" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "web" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "web" rollout to finish: 1 out of 2 new replicas have been updated...
Waiting for deployment "web" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "web" rollout to finish: 1 old replicas are pending termination...
deployment "web" successfully rolled out
[root@master ~]# kubectl rollout undo --help
Rollback to a previous rollout.
Examples:
# Rollback to the previous deployment
kubectl rollout undo deployment/abc
# Rollback to daemonset revision 3
kubectl rollout undo daemonset/abc --to-revision=3
# Rollback to the previous deployment with dry-run
kubectl rollout undo --dry-run=server deployment/abc
Options:
--allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in
the template. Only applies to golang and jsonpath output formats.
--dry-run='none': Must be "none", "server", or "client". If client strategy, only print the object that would be
sent, without sending it. If server strategy, submit server-side request without persisting the resource.
-f, --filename=[]: Filename, directory, or URL to files identifying the resource to get from a server.
-k, --kustomize='': Process the kustomization directory. This flag can't be used together with -f or -R.
-o, --output='': Output format. One of:
json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file.
-R, --recursive=false: Process the directory used in -f, --filename recursively. Useful when you want to manage
related manifests organized within the same directory.
--template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The
template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
--to-revision=0: The revision to rollback to. Default to 0 (last revision).
Usage:
kubectl rollout undo (TYPE NAME | TYPE/NAME) [flags] [options]
Use "kubectl options" for a list of global command-line options (applies to all commands).
#回滚到指定的版本
[root@master ~]# kubectl rollout undo deployment web --to-revision=3
deployment.apps/web rolled back
[root@master ~]# kubectl rollout status deployment web
Waiting for deployment "web" rollout to finish: 1 old replicas are pending termination...
Waiting for deployment "web" rollout to finish: 1 old replicas are pending termination...
deployment "web" successfully rolled out
弹性伸缩
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d2h
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d2h
web-586db47859-gr8wj 1/1 Running 0 3m28s
web-586db47859-hnp7f 1/1 Running 0 3m44s
[root@master ~]# kubectl scale deployment web --replicas=10
deployment.apps/web scaled
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d2h
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d2h
web-586db47859-22g6n 0/1 ContainerCreating 0 19s
web-586db47859-5j8x7 0/1 ContainerCreating 0 19s
web-586db47859-9vn5m 0/1 ContainerCreating 0 19s
web-586db47859-gr8wj 1/1 Running 0 4m36s
web-586db47859-gsgn8 0/1 ContainerCreating 0 19s
web-586db47859-hnp7f 1/1 Running 0 4m52s
web-586db47859-n4wbm 0/1 ContainerCreating 0 19s
web-586db47859-s228l 0/1 ContainerCreating 0 19s
web-586db47859-tmp54 0/1 ContainerCreating 0 19s
web-586db47859-wkj8s 0/1 ContainerCreating 0 19s
[root@master ~]# kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6799fc88d8-kqfmm 1/1 Running 3 2d2h
tomcat-7d987c7694-8sjkd 1/1 Running 2 2d2h
web-586db47859-22g6n 1/1 Running 0 93s
web-586db47859-5j8x7 1/1 Running 0 93s
web-586db47859-9vn5m 1/1 Running 0 93s
web-586db47859-gr8wj 1/1 Running 0 5m50s
web-586db47859-gsgn8 1/1 Running 0 93s
web-586db47859-hnp7f 1/1 Running 0 6m6s
web-586db47859-n4wbm 1/1 Running 0 93s
web-586db47859-s228l 1/1 Running 0 93s
web-586db47859-tmp54 1/1 Running 0 93s
web-586db47859-wkj8s 1/1 Running 0 93s
B站学习网址:k8s教程由浅入深-尚硅谷哔哩哔哩bilibili