江小南

V1

2022/10/23阅读:28主题:默认主题

【CKA、CKS篇】CKA真题解析——扩容 deployment 副本数量

真题解析

题目

将 deployment presentation 扩展至 4 个pods。

考察点

容器扩缩容

解析

  1. 查看原有 deployment presentation 的副本数。
  2. 将副本数 扩展至 4 个。

帮助命令

candidate@node01:~$ kubectl get deployment -h
Display one or many resources.
...
Usage:
  kubectl get
[(-o|--output=)json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-as-json|jsonpath-file|custom-columns|custom-columns-file|wide]
(TYPE[.VERSION][.GROUP] [NAME | -l label] | TYPE[.VERSION][.GROUP]/NAME ...) [flags] [options]

Use "kubectl options" for a list of global command-line options (applies to all commands).
candidate@node01:~$
candidate@node01:~$ kubectl scale deployment -h
Set a new size for a deployment, replica set, replication controller, or stateful set.
...
Usage:
  kubectl scale [--resource-version=version] [--current-replicas=count] --replicas=COUNT (-f FILENAME | TYPE NAME)
[options]

Use "kubectl options" for a list of global command-line options (applies to all commands).
candidate@node01:~$

实际操作

candidate@node01:~$ kubectl get deployment presentation -o wide
NAME           READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES              SELECTOR
presentation   1/1     1            1           45d   nginx        vicuu/nginx:hello   app=presentation
candidate@node01:~$
candidate@node01:~$ kubectl get pod -l app=presentation
NAME                            READY   STATUS    RESTARTS        AGE
presentation-5f64bd874c-68z8p   1/1     Running   6 (7m40s ago)   45d
candidate@node01:~$

可以发现现有的 deployment presentation 有1个副本。现将其进行扩展。

candidate@node01:~$ kubectl scale deployment presentation --replicas=4
deployment.apps/presentation scaled
candidate@node01:~$ 

检查验证

candidate@node01:~$ kubectl get deployment presentation -o wide
NAME           READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES              SELECTOR
presentation   4/4     4            4           45d   nginx        vicuu/nginx:hello   app=presentation
candidate@node01:~$ kubectl get pod -l app=presentation
NAME                            READY   STATUS    RESTARTS      AGE
presentation-5f64bd874c-2nwgn   1/1     Running   0             65s
presentation-5f64bd874c-68z8p   1/1     Running   6 (10m ago)   45d
presentation-5f64bd874c-gw6dv   1/1     Running   0             65s
presentation-5f64bd874c-qc7qz   1/1     Running   0             65s
candidate@node01:~$

发现成功将副本数扩展到了4个。

至此本道题目完成。

扩展知识

对于副本数的修改,除了上述的命令行的方式,我们还可以通过修改yaml的方式操作。

比如现在将副本数修改为5个。

candidate@node01:~$ kubectl edit deployment presentation
deployment.apps/presentation edited
candidate@node01:~$

replicas的值修改为相应的数字即可。效果如下:

candidate@node01:~$ kubectl get deployment presentation -o wide
NAME           READY   UP-TO-DATE   AVAILABLE   AGE   CONTAINERS   IMAGES              SELECTOR
presentation   5/5     5            5           45d   nginx        vicuu/nginx:hello   app=presentation
candidate@node01:~$ kubectl get pod -l app=presentation
NAME                            READY   STATUS    RESTARTS      AGE
presentation-5f64bd874c-68z8p   1/1     Running   6 (18m ago)   45d
presentation-5f64bd874c-94whx   1/1     Running   0             3m3s
presentation-5f64bd874c-qxq5h   1/1     Running   0             3m3s
presentation-5f64bd874c-rt7zg   1/1     Running   0             3m3s
presentation-5f64bd874c-thdns   1/1     Running   0             3m3s
candidate@node01:~$

分类:

后端

标签:

云计算

作者介绍

江小南
V1