CKA真题:题目和解析-4
所有命令都验证过,有更好的方式,欢迎留言~~~CKA习题和真题汇总CKA考试经验:报考和考纲CKA :2019年12月英文原题和分值CKA考试习题:K8S基础概念--API 对象CKA考试习题:调度管理-nodeAffinity、podAffinity、TaintsCKA考试习题:K8S日志、监控与应用管理CKA考试习题:网络管理-Pod网络、...
所有命令都验证过,有更好的方式,欢迎留言~~~
CKA 习题和真题汇总
- CKA考试习题:K8S基础概念--API 对象
- CKA考试习题:调度管理- nodeAffinity、podAffinity、Taints
- CKA考试习题:K8S日志、监控与应用管理
- CKA考试习题:网络管理-Pod网络、Ingress、DNS
- CKA考试习题:存储管理-普通卷、PV、PVC
- CKA考试习题:安全管理--Network Policy、serviceaccount、clusterrole
- CKA考试习题:k8s故障排查
- CKA真题:题目和解析-1
- CKA真题:题目和解析-2
- CKA真题:题目和解析-3
- CKA真题:题目和解析-4
- CKA真题:题目和解析-5
- CKA真题:题目和解析-6
更多CKA资料或交流:可加 wei xin :wyf19910905
13、不要以持久卷方式挂载
Set configuration context $ kubectl config use-context k8s
Create a pod as follow:
Name:non-persistent-redis
Container image: redis
Name-volume with name: cache-control
Mount path: /data/redis
It should launch in the pre-pod namespace and the volums MUST NOT be persistent
创建一个pod,名为non-presistent-redis,
挂载存储卷,卷名为:cache-control,挂载到本地的:/data/redis目录下,
在名称空间pre-prod里做,不要以持久卷方式挂载。
解析:
没有明确要求挂载在node主机上的具体位置,使用随机位置emptyDir:{} ,
如果明确挂载到主机的指定位置和地址,则使用hostPath
答:
emptyDir:{}
[root@vms31 opt]# kubectl run non-persistent-redis --image=redis --generator=run-pod/v1 --dry-run -o yaml > ./13.yaml
[root@vms31 opt]# vim 13.yaml
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: non-persistent-redis
name: non-persistent-redis
spec:
volumes:
- name: cache-control
emptyDir: {}
containers:
- image: redis
imagePullPolicy: IfNotPresent
name: non-persistent-redis
resources: {}
volumeMounts:
- mountPath: /data/redis
name: cache-control
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
[root@vms31 opt]# kubectl create ns pre-pod
namespace/pre-pod created
[root@vms31 opt]# kubectl get ns
NAME STATUS AGE
default Active 174d
kube-public Active 174d
kube-system Active 174d
ns001 Active 174d
pre-pod Active 5s
production Active 174d
website-frontend Active 1h
[root@vms31 opt]# kubectl apply -f 13.yaml -n pre-pod
pod/non-persistent-redis created
[root@vms31 opt]# kubectl get pods -n pre-pod
NAME READY STATUS RESTARTS AGE
non-persistent-redis 1/1 Running 0 9s
hostPath
apiVersion: v1
kind: Pod
metadata:
name: non-presistent-redis
namespace: pre-prod
spec:
containers:
- image: redis
name: redis
volumeMounts:
- mountPath: /data/redis
name: cache-control
volumes:
- name: cache-control
hostPath:
# directory location on host
path: /data/redis
# this field is optional
type: DirectoryOrCreate
官方文档:
https://kubernetes.io/docs/concepts/storage/volumes/
https://kubernetes.io/docs/concepts/storage/volumes/#emptydir
14、Scale:扩缩容
Set configuration context $ kubectl config use-context k8s
Scale the deployment webserver to 6 pods
答:
[root@vms31 opt]# kubectl get deployments.
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx-app 3 3 3 3 11h
webserver 1 1 1 1 174d
[root@vms31 opt]# kubectl scale deployment/webserver --replicas=6
deployment.extensions/webserver scaled
[root@vms31 opt]# kubectl get deployments.
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
nginx-app 3 3 3 3 11h
webserver 6 6 6 1 174d
官网链接: https://kubernetes.io/docs/reference/kubectl/cheatsheet/
15、统计node是ready状态,(不包含node的污点,没有调度的)
Set configuration context $ kubectl config use-context k8s
check to see how many nodes are ready (not including nodes tained NoSchedule) and write the number to /opt/nodenum
检查有多少nodes是ready状态,(不包含node的污点,没有调度的),写入数量到 /opt/nodenum
答:
# grep -w是精确匹配
# 通过下面命令,统计Ready数量N
kubectl get node | grep -w Ready | wc -l
# 通过下面命令,统计NoSchedule和Taints数量M
kubectl describe nodes | grep Taints | grep -I NoSchedule | wc -l
# 答案填写N减去M得到的值
echo 2 > /opt/nodenum
16、统计pod的CPU
Set configuration context $ kubectl config use-context k8s
From the pod label name=cpu-utilizer, find pods running high CPU workloads and write the name of the pod consuming most CPU to the file /opt/cpu.txt
从标签为 name=cpu-utilizer的所有pod里面,找出cpu使用最高的那个pod,并写入到/opt/cpu.txt(这个文件已经存在)
答:
kubectl top pods -l name=cpu-utilizer -n kube-system
echo '[找到的pod名]' >> /opt/cpu.txt
# 如果是找node,则使用
kubectl top nodes
更多推荐
所有评论(0)