当前位置: 首页 > article >正文

CKA 不假题 练习笔记 (四)

Q 13: Sidecar Container/Logging

本题目,Logging是目的;Sidecar是手段
Context -
An existing Pod needs to be integrated into the Kubernetes built-in logging architecture (e.g. kubectl logs). Adding a streaming sidecar container is a good and common way to accomplish this requirement.

Task -
Add a sidecar container named sidecar, using the busybox image, to the existing Pod big-corp-app. The new sidecar container has to run the following command:
ls
Use a Volume, mounted at /var/log, to make the log file big-corp-app.log available to the sidecar container.

Q13: 解答(来自chatgpt)

Updated Pod YAML Manifest
This assumes you have access to edit the existing Pod big-corp-app. Save the updated configuration to a file (e.g., big-corp-app.yaml) and apply it:

apiVersion: v1
kind: Pod
metadata:
  name: big-corp-app
spec:
  containers:
  - name: main-container
    image: your-app-image
    volumeMounts:
    - name: log-volume
      mountPath: /var/log
    command: ["/bin/sh", "-c"]
    args: ["echo 'Hello from main container!' >> /var/log/big-corp-app.log; sleep 3600"]
  - name: sidecar  #需要新增部分sidecar 边车容器
    image: busybox #采用最小的image
    volumeMounts:
    - name: log-volume
      mountPath: /var/log
    command: ["/bin/sh", "-c"]
    args: ["tail -f /var/log/big-corp-app.log"]
  volumes: # main-container和sidecar 共用一个volume
  - name: log-volume
    emptyDir: {} 

【追加备注】

  1. 此题目其实属于Logging相关,而不是Pod。
  2. 通过Sidecar模式,运行一个1MB大小的busybox 来收集同一个pod里的应用Container的日志是一个较为流行的最佳实践。

Q14: Kubectl TOP

Task -
From the pod label name=overloaded-cpu, find pods running high CPU workloads and write the name of the pod consuming most CPU to the file /opt/
KUTR00401/KUTR00401.txt (which already exists).

Q14:解答

root@master:/opt/k8sconfig$sudo kubectl top pods -l name=voerloaded-cpu --sort-by=cpu

Q15: kubelet

Task -
A Kubernetes worker node, named wk8s-node-0 is in state NotReady.
Investigate why this is the case, and perform any appropriate steps to bring the node to a Ready state, ensuring that any changes are made permanent.
(这个题目其实是因为node上的kubelet停止了导致了node不ready)

Q16: PVC

Task -
Create a new PersistentVolumeClaim:
✑ Name: pv-volume
✑ Class: csi-hostpath-sc
✑ Capacity: 10Mi
Create a new Pod which mounts the PersistentVolumeClaim as a volume:
✑ Name: web-server
✑ Image: nginx
✑ Mount path: /usr/share/nginx/html
Configure the new Pod to have ReadWriteOnce access on the volume.
Finally, using kubectl edit or kubectl patch expand the PersistentVolumeClaim to a capacity of 70Mi and record that change.

Q16: 解答

pvc-pv-volume.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-volume
spec:
  storageClassName: csi-hostpath-sc
  capacity:
    storage: 10Mi

https://kubernetes.io/docs/concepts/storage/persistent-volumes/

pod-web-server.yaml

apiVersion: v1
kind: Pod
metadata:
  name: pv-volume-pod
spec:
  containers:
  - name: web-server
    image: nginx
    volumeMounts:
    - name: pv-test
      mountPath: /usr/share/nginx/html
  volumes:
  - name: pv-test
    persistentVolumeClass: csi-hostpath-sc
      Cliamname: pv-volume

kubectl edit pvc pv-volume 此命令去edit storage

Q17: NGINX-Ingress

Task -
Create a new nginx Ingress resource as follows:
✑ Name: pong
✑ Namespace: ing-internal
✑ Exposing service hello on path /hello using service port 5678

Q17: 解答

考试时候,先定位到kubernets官网上关于ingress部分,然后copy里面的yaml example 改写即可

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: pong
  namespace: ing-internal
spec:
  ingressClassName: nginx # 定义ingress的类型为nginx,通常nginx是default,可以不显性设定
  rules:
  - http:
      paths:
      - path: /hello
        pathType: Prefix
        backend:
          service:
            name: hello # backend的service是“hello”
            port:
              number: 5678

【追加备注】

  1. 此题目可能需要先通过kubectl get ingressclass 来确认下是否已经存在ingress class,如果没有可能需要新建ingressclass。
  2. CNCF将不早于2025年2月10日开始换题,根据新的考试内容,ingress相关题目大概率会被Gateway API取代!

Q18:Pod

Task -
Schedule a Pod as follows:

• Name: kucc1
• App Containers: 2
• Container Name/images:
o redis
o consul

Q18:解答

考试时候,先定位到kubernets官网上关于pod部分,然后copy里面的yaml example 改写即可。

apiVersion: v1
kind: Pod
metadata:
  name: kucc1
spec:
  containers:
  - name: redis
    image: redis
    imagePullPolicy: IfNotPresent #非必须要定义
 - name: consul
    image: consul
    imagePullPolicy: IfNotPresent #非必须要定义

本人准备CKA考试的笔记全部完成,不承诺答案一定正确,请独立思考。


http://www.kler.cn/a/530073.html

相关文章:

  • 智能小区物业管理系统打造高效智能社区服务新生态
  • R 字符串:深入理解与高效应用
  • Java小白入门教程:LinkedList
  • 【Android】布局文件layout.xml文件使用控件属性android:layout_weight使布局较为美观,以RadioButton为例
  • MySQL 插入数据
  • DS并查集(17)
  • 80-《红球姜》
  • 在实际开发中,如何正确使用 INT(1) 和 INT(10)
  • 动态规划学习
  • Rust语言的编程范式
  • 虚幻UE5手机安卓Android Studio开发设置2025
  • 996引擎-地图:动态创建副本地图
  • 音视频入门基础:RTP专题(7)——RTP协议简介
  • 第一篇:从技术架构视角解析DeepSeek的AI底层逻辑
  • 揭秘算法 课程导读
  • 复制粘贴小工具——Ditto
  • 【系统架构设计师】真题论文: 论微服务架构及其应用(包括解题思路和素材)
  • AI智慧社区--Excel表的导入导出
  • < 自用文儿 使用 acme 获取网站证书 > ACME 脚本 script: acme.sh 获得证书 觉得比 certbot 方便
  • 深入理解计算机系统:揭开计算机科学的神秘面纱
  • MFC程序设计(六)消息和控件
  • Spring Boot 实例解析:配置文件占位符
  • DeepSeek R1 本地部署安装包下载 及 本地部署教程
  • 【机器学习与数据挖掘实战】案例11:基于灰色预测和SVR的企业所得税预测分析
  • 【LeetCode 刷题】回溯算法-子集问题
  • CTFSHOW-WEB入门-命令执行54-70