Files
kuboard-press/t/cka/daily/001.md
2020-12-24 13:57:19 +08:00

168 lines
5.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
vssueId: 163
# layout: StepLayout
sharingTitle: CKA备考每日一题 - Day 1
description: CKA备考每日一题 - Day 1
meta:
- name: keywords
content: Kubernetes,K8S,CKA,Certified Kubernetes Administrator
---
# CKA每日一题 --- Day 1
<AdSenseTitle/>
**今日考题**
以下 Daemonset yaml 中,哪些是正确的?(多选)
A.
``` yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: default
labels: k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
containers:
- name: fluentd-elasticsearch
image: gcr.io/fluentd-elasticsearch/fluentd:v2.5.1
restartPolicy: Never
```
B.
``` yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: default
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels: name: fluentd-elasticsearch
spec:
containers:
- name: fluentd-elasticsearch
image: gcr.io/fluentd-elasticsearch/fluentd:v2.5.1
restartPolicy: Onfailure
```
C.
``` yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: default
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels: name: fluentd-elasticsearch
spec:
containers:
- name: fluentd-elasticsearch
image: gcr.io/fluentd-elasticsearch/fluentd:v2.5.1
restartPolicy: Always
```
D.
``` yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd-elasticsearch
namespace: default
labels:
k8s-app: fluentd-logging
spec:
selector:
matchLabels:
name: fluentd-elasticsearch
template:
metadata:
labels:
name: fluentd-elasticsearch
spec:
containers:
- name: fluentd-elasticsearch
image: gcr.io/fluentd-elasticsearch/fluentd:v2.5.1
```
<b-button v-b-toggle.collapse-join-error variant="danger" size="sm" style="margin-top: 1rem;" v-on:click="$sendGaEvent('cka-daily', 'cka-daily', 'CKA每日一题001')">答案及解析</b-button>
<b-collapse id="collapse-join-error" class="mt-2">
<b-card style="background-color: rgb(254, 240, 240); border: solid 1px #F56C6C;">
**答案: C、D**
在考试时只允许有考试网站和k8s两个标签页。所以平常学习时尽可能去找文档去学习才是最权威的。熟悉 [https://kubernetes.io/concepts/](https://kubernetes.io/concepts/) 目录下的内容对考试通过非常有帮助。
[https://kuboard.cn/learning/](https://kuboard.cn/learning/) 目录下提供了 [https://kubernetes.io/concepts/](https://kubernetes.io/concepts/) 目录下的中文翻译,可以对照着学习。
以这个问题为例直接打开daemonset的说明文档见以下链接
[https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/)
![img](./001.assets/640.jpeg)
> A Pod Template in a DaemonSet must have a RestartPolicy equal to Always, or be unspecified, which defaults to Always. Daemonset里的pod Template下必须有RestartPolicy如果没指定会默认为Always
在 [https://kuboard.cn](https://kuboard.cn) 上也可以找到对应的中文内容:
[https://kuboard.cn/learning/k8s-intermediate/workload/wl-daemonset/create.html](https://kuboard.cn/learning/k8s-intermediate/workload/wl-daemonset/create.html)
![image-20191120225243614](./001.assets/image-20191120225243614.png)
restartPolicy 字段,可选值为 Always、OnFailure 和 Never。默认为 Always。一个Pod中可以有多个容器restartPolicy适用于Pod 中的所有容器。restartPolicy作用是让kubelet重启失败的容器。
另外Deployment、Statefulset的restartPolicy也必须为Always保证pod异常退出或者健康检查 livenessProbe失败后由kubelet重启容器。[https://kubernetes.io/zh/docs/concepts/workloads/controllers/deployment](https://kubernetes.io/zh/docs/concepts/workloads/controllers/deployment) 或者 [https://kuboard.cn/learning/k8s-intermediate/workload/wl-deployment](https://kuboard.cn/learning/k8s-intermediate/workload/wl-deployment)
Job和CronJob是运行一次的podrestartPolicy只能为OnFailure或Never确保容器执行完成后不再重启。[https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/](https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/) 或者 [https://kuboard.cn/learning/k8s-intermediate/workload/wl-job/](https://kuboard.cn/learning/k8s-intermediate/workload/wl-job/)
> 实际考试以上机实操为主
</b-card>
</b-collapse>
> CKA 考试每日一题系列,全部内容由 [我的小碗汤](https://mp.weixin.qq.com/s/5tYgb_eSzHz_TMsi0U32gw) 创作,本站仅做转载
<JoinCKACommunity/>