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

3.1 KiB
Raw Blame History

vssueId, sharingTitle, description, meta
vssueId sharingTitle description meta
170 CKA备考打卡 - 每日一题 - Day 12 CKA备考打卡 - 每日一题 - Day 12
name content
keywords Kubernetes,K8S,CKA,Certified Kubernetes Administrator

CKA每日一题 --- Day 12

::: tip 考题

Set configuration context $ kubectl config use-context wk8s

configure the kubelet systemed managed service, on the node labelled with name=wk8s-node-1,to launch a pod containing a single container of image nginx named myservice automatically.

Any spec file requried should be placed in the /etc/kuberneteds/mainfests directory on the node

Hints:

You can ssh to the failed node using $ ssh wk8s-node-0

You can assume elevated privileges on the node with the following command $ sudo -i

请给出操作步骤。

:::

答案及解析

答案

切换至wk8s上下文

kubectl config use-context wk8s

查看有labelname=wk8s-node-1的node的信息

kubectl get nodes -l name=wk8s-node-1 -o wide

登录指定的机器,并获得操作权限。

ssh wk8s-node-0
sudo -i

查看kubelet服务启动参数--config

systemctl status kubelet -l

在--config指定的文件中找到staticPodPath文件目录

# cat /var/lib/kubelet/config.yaml|grep staticPodPath
staticPodPath: /etc/kubernetes/manifests

在静态pod目录下创建yaml使用下面命令生成符合要求的myservice.yaml等待kubelet自动拉起静态pod

kubectl run myservice --image=nginx --generator=run-pod/v1 --dry-run -o yaml > myservice.yaml

解析

context相关操作官方命令指南 https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#config

Create static Pods说明 https://kubernetes.io/docs/tasks/configure-pod-container/static-pod/

本题主要考kubelet的配置以及Static Pod的创建。

可以通过systemctl status kubelet -l查看kubelet进程的配置文件路径。

Kubernetes_CKA_每日一题

以及通过配置文件config.yaml找到staticPodPath

Kubernetes_CKA_每日一题

有时候,情况可能会不一样,systemctl status kubelet -l查到的10-kubeadm.conf中没有config.yaml配置:

Kubernetes_CKA_每日一题

而是将其直接用--pod-manifest-path传入,所以这种情况就需要修改10-kubeadm.conf中的配置路径(如果路径不是期望路径)

--pod-manifest-path=/etc/kubernetes/manifests

修改后需要重启kubelet

systemctl start kubelet

CKA 考试每日一题系列,全部内容由 我的小碗汤 创作,本站仅做转载