CKA真题:题目和解析-6

所有命令都验证过,有更好的方式,欢迎留言~~~

CKA 习题和真题汇总

更多CKA资料或交流:可加 wei  xin :wyf19910905

21、Create static Pods

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

配置一个kubelet 系统管理的服务,在标签为name1=wk8s-node-1的节点上配置,要包含一个POD名为myservice的镜像nginx 容器。

所需的任何特定文件应放在/etc/kubernetes/manifests 的节点文件夹内

解析:

给出一个节点,完善kubelet配置文件,要求使用systemd配置kubelet

Static Pods are managed directly by the kubelet daemon on a specific node, without the API server observing them. Unlike Pods that are managed by the control plane (for example, a Deployment); instead, the kubelet watches each static Pod (and restarts it if it crashes).

Static Pods are always bound to one Kubelet on a specific node.

答:

首先,staticPod是固定在某个node上面,由kubelet管理生成的一种pod。

具体生成方式是:kubelet扫描固定的文件夹,找到yaml文件统一进行生成

  1. 查找到staticPod的固定文件夹 :systemctl status kubelet
  2. 在该文件夹中添加自己的yaml文件 :kubectl run myservice --image=nginx --generator=run-pod/v1 --dry-run -o yaml >21.yml
  3. 重新启动kubelet :systemctl daemon-reload       systemctl restart kubelet

这样之后,在指定文件夹下面的yaml文件就都会以staticPod的形式运行起来。

# 1.进入 wk8s-node-1 节点
ssh wk8s-node-1

# 2. 在/etc/kubernetes/manifests 定义pod的yaml文件
#使用下面的参考命令生成pod文件
kubectl run myservice --image=nginx --generator=run-pod/v1 --dry-run -o yaml >21.yml

# 3. 在 wk8s-node-1 节点上配置kubelet 
# 3.1 方式一:编辑kubelet配置( /usr/lib/systemd/system/kubelet.service.d)
# 添加参数 --pod-manifest-path=/etc/kubernetes/manifests 

KUBELET_ARGS="--cluster-dns=10.254.0.10 --cluster-domain=kube.local --pod-manifest-path=/etc/kubernetes/manifests"

# 3.2 方式二: 在kubelet配置(--config=/var/lib/kubelet/config.yaml)文件中
# 添加   staticPodPath: /etc/kubernetes/manifests


#4. 重启服务
systemctl daemon-reload
systemctl restart kubelet
systemctl enable kubelet
补充:

#重新载入 systemd,扫描新的或有变动的单元
systemctl daemon-reload		

官网链接:

https://kubernetes.io/docs/tasks/administer-cluster/static-pod/

https://kubernetes.io/docs/tasks/configure-pod-container/static-pod/#static-pod-creation

22 .给出一个集群,将节点node1添加到集群中,并使用TLS bootstrapping

详见:

23、集群故障排查(kubelet配置的静态Pod路径)

Set configuration context $ kubectl config use-context bk8s

Given a partially-funnctioning Kubernetes cluster,identify symptoms of failure on the cluster.

Determine the node,the failing service and take actions to bring up the failed service and restore the health of the cluster.

Ensure that any changes are made permanently.

The worker node in this cluster is labelled with name=bk8s-node-0

Hints:

You can ssh to the relevant nodes using $ ssh $(NODE) where $(NODE) is one of bk8s-master-0 or bk8s-node-0

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

给定一个部分功能正常的Kubernetes集群,识别集群上的故障症状。

确定节点、failling服务器并采取行动启动失败的服务并恢复集群的健康状态,确保永久地进行任何更改。

这个集群中的工作节点被标记为name=bk8 -node-0

答:

解题思路:

1.ssh到=bk8s-node-0先判断此集群的搭建方式,是用kubeadm方式搭建还是用二进制方式搭建

  • 查看/etc/kubernetes/manifests 里有没有etcd、kube-apiserver.yaml、kube-controller-manager.yaml、schedule.yaml,如果有这4个文件,则是以kubeadm方式安装,实现方式为静态Pod方式实现
    • 找到kubelet服务加载的配置文件,在里面加上静态pod的路径即可
    • 如果controller-manager是以服务的方式启动的,则start controller-manager服务。

2.  kubelet安装后,启动方式有好几种,考试环境是修改加载的kubelet.service文件,

      在里面加上--manifest-url=/etc/kubernetes/manifests

      我这个环境是在/var/lib/kubelet/config.yaml 里加入(--config=/var/lib/kubelet/config.yaml )

3.重启kubelet服务 即可。

切换集群以后:

1,执行:kubectl get nodes     pods    cs等命令,发现执行不了,报错。
  返回xxx.xxx.xxx.xxx:6443 ………..

 

2,ssh登陆到wk8s -master-0上检查服务,如master上的4大服务,

api-server/schedule/controllor-manager/etcd

 

systemctl list-unit-files | grep controller-manager    没有服务

systemctl list-unit-files | grep api-server       没有服务

 

3,此刻进入/etc/kubernetes/manifest文件夹中,可以看到api-server.yaml  controller-manager.yaml等4个文件。

 

4, systemctl status kubelet  看到启动正常启动的,
说明api-server、controlloer-manager、etcd、schedule这几个pod 没启动,检查静态pod配置.

 

考试环境把正确的/etc/kubernetes/manifest  换成了/etc/kubernetes/DODKSIYF 路径,
此路径并不存在,
把这个错误的路径换成到存放api/controller-manager/etcd/schedule这几个yaml文件存放的路径,
重启Kubelet,排错完成。

 

再查看node啥的,就OK了

kubectl get cs 能看到controller manager 没有启动

登陆到master上
找到相关服务重启

systemctl start kube-manager-controller.service

查看kubelet的配置文件-静态pod路径

k8s1.13以上

# 找到config配置
systemctl status kubelet


# 在结果查找config 配置信息
/usr/bin/kubelet
--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf
--kubeconfig=/etc/kubernetes/kubelet.conf --config=/var/lib/kubelet/config.yaml
--cgroup-driver=systemd--network...

# 查找静态pod配置路径
cat /var/lib/kubelet/config.yaml
cat /var/lib/kubelet/config.yaml | grep staticPodPath

staticPodPath:/etc/kubernetes/manifests

k8s1.9

# 找到config配置
systemctl status kubelet


# 在结果查找--pod-manifest-path配置信息

24、持久卷

Set configuration context $ kubectl config use-context hk8s

Create a persistent volume with name app-config of capacity 1Gi and access mode ReadWriteOnce.

The type of volume is hostPath and its location is /srv/app-config

创建一个持久卷,名称为app-config,容量为1Gi,访问模式为ReadWriteOnce

卷的类型是hostPath,它的位置是/srv/app-confi

答:

# vim persistent.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: app-config
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /srv/app-config

# kubectl apply -f persistent.yaml

官网链接:https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistent-volumes

发布了389 篇原创文章 · 获赞 1041 · 访问量 163万+

猜你喜欢

转载自blog.csdn.net/fly910905/article/details/103232471