Bootstrap

CKA 不假题 练习笔记 (三)

Q6 Pod and Service

Task -
Reconfigure the existing deployment front-end and add a port specification named http exposing port 80/tcp of the existing container nginx.
Create a new service named front-end-svc exposing the container port http.
Configure the new service to also expose the individual Pods via a NodePort on the nodes on which they are scheduled.

TBD

Q7 Kubectl scale

Task -
Scale the deployment $ds-name to 3 pods.

Q7 解答

我使用的测试deployment是storage-test

root@master:/opt/k8sconfig$sudo kubectl scale deployment/storage-test  --replicas=2
deployment.apps/storage-test scaled
root@master:/opt/k8sconfig$ kubectl get deployment 
NAME           READY   UP-TO-DATE   AVAILABLE   AGE
storage-test   2/2     2            2           2d20h # replica 是2个了现在
root@master:/opt/k8sconfig$sudo kubectl scale deployment/storage-test  --replicas=1 #测试下是否可以收缩
deployment.apps/storage-test scaled
root@master:/opt/k8sconfig# kubectl get deployment 
NAME           READY   UP-TO-DATE   AVAILABLE   AGE
storage-test   1/1     1            1           2d20h #测试结果符合预期

Q8 Pods

Task -
Schedule a pod as follows:
✑ Name: nginx-kusc00401
✑ Image: nginx
✑ Node selector: disk=ssd

Q8 解答 YAML

实际生产环境, 应该由deplopyment 或者daemenset等自动生成pod,不要手工创建pod和replica吧。

apiVersion: v1
kind: Pod
metadata:
  name: nginx-kusc00401
  labels:
    app: nginx
spec:
  containers:
  - name: nginx
    image: nginx
  nodeSelector: #本题目key point
    disk: ssd

Q9 Nodes Status/Taints

Task -
Check to see how many nodes are ready (not including nodes tainted NoSchedule) and write the number to /opt/KUSC00402/kusc00402.txt.

Q9 解答

root@master:/opt/k8sconfig$sudo kubectl get node
NAME     STATUS   ROLES           AGE   VERSION
master   Ready    control-plane   15d   v1.32.1
slave1   Ready    <none>          15d   v1.32.1
slave2   Ready    <none>          15d   v1.32.1

root@master:/opt/k8sconfig$sudo kubectl describe nodes |grep NoSchedule
Taints:             node-role.kubernetes.io/control-plane:NoSchedule
# control-plane 默认是不调度pod的(tainted NoSchedule!!)所以答案是2!

Q10 Pods

Task -
Schedule a Pod as follows:
✑ Name: kucc8
✑ App Containers: 2
✑ Container Name/Images:

  • nginx
  • consul
root@master:/opt/k8sconfig$sudo kubectl run kucc8 --image=nginx --dry-run -o yaml > app.yml
W0127 19:39:01.593926 1928706 helpers.go:702] --dry-run is deprecated and can be replaced with --dry-run=client.
root@master:/opt/k8sconfig$suod cat app.yml #vim修改前
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: kucc8
  name: kucc8
spec:
  containers:
  - image: nginx
    name: kucc8
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
root@master:/opt/k8sconfig$sudo vim app.yml 
root@master:/opt/k8sconfig$sudo cat app.yml #vim修改后
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: kucc8
  name: kucc8
spec:
  containers:
  - image: nginx
    name: nginx
  containers:
  - image: consul
    name: consul

root@master:/opt/k8sconfig$sudo kubectl apply -f app.yml 
pod/kucc8 created # 成功创建

;