CKAD-prep-notes练习题库:5个必备的Kubernetes应用开发实践题目
【免费下载链接】ckad-prep-notesList of resources and notes for passing the Certified Kubernetes Application Developer (CKAD) exam.项目地址: https://gitcode.com/gh_mirrors/ck/ckad-prep-notes
CKAD-prep-notes是专为Certified Kubernetes Application Developer (CKAD)考试打造的备考资源集合,包含了丰富的学习笔记和实践题目,帮助开发者快速掌握Kubernetes应用开发核心技能。本文精选5个必备的Kubernetes应用开发实践题目,覆盖考试重点难点,助你高效备考,轻松通过CKAD认证!
1. 快速创建多副本Deployment并实现滚动更新 🚀
题目要求:使用kubectl命令快速创建一个名为nginx-deploy的Deployment,包含3个副本,使用nginx:1.14镜像。然后将镜像更新为nginx:1.19并观察滚动更新过程,最后回滚到之前的版本。
核心考点:Deployment创建、滚动更新与回滚
解题步骤:
# 创建Deployment kubectl create deployment nginx-deploy --image=nginx:1.14 --replicas=3 # 查看Deployment状态 kubectl get deployments # 执行滚动更新 kubectl set image deployment/nginx-deploy nginx=nginx:1.19 # 监控更新进度 kubectl rollout status deployment/nginx-deploy # 回滚到上一版本 kubectl rollout undo deployment/nginx-deploy技巧提示:利用kubectl rollout history deployment/nginx-deploy可查看部署历史记录,通过--to-revision参数可回滚到指定版本。
2. 使用ConfigMap和Secret配置应用 🔒
题目要求:创建一个ConfigMapapp-config存储应用配置APP_COLOR=blue和APP_MODE=prod,创建一个Secretapp-secret存储敏感信息DB_PASSWORD=secretpass。然后创建一个Podconfig-demo,通过环境变量方式引用这些配置。
核心考点:ConfigMap、Secret创建与使用
解题步骤:
# 创建ConfigMap kubectl create configmap app-config --from-literal=APP_COLOR=blue --from-literal=APP_MODE=prod # 创建Secret kubectl create secret generic app-secret --from-literal=DB_PASSWORD=secretpass # 创建Pod引用配置 kubectl run config-demo --image=nginx --restart=Never --env="APP_COLOR=$(kubectl get configmap app-config -o jsonpath='{.data.APP_COLOR}')" --env="DB_PASSWORD=$(kubectl get secret app-secret -o jsonpath='{.data.DB_PASSWORD}' | base64 -d)"验证方法:通过kubectl exec -it config-demo -- env命令检查环境变量是否正确注入。
3. 配置Pod资源限制与探针 📊
题目要求:创建一个名为resource-demo的Pod,使用nginx镜像。为其配置资源请求(CPU: 100m, 内存: 128Mi)和资源限制(CPU: 200m, 内存: 256Mi)。同时添加存活探针(livenessProbe)和就绪探针(readinessProbe),通过HTTP方式检查/index.html路径。
核心考点:资源管理、健康检查
解题步骤:
apiVersion: v1 kind: Pod metadata: name: resource-demo spec: containers: - name: nginx image: nginx resources: requests: cpu: 100m memory: 128Mi limits: cpu: 200m memory: 256Mi livenessProbe: httpGet: path: /index.html port: 80 initialDelaySeconds: 5 periodSeconds: 10 readinessProbe: httpGet: path: /index.html port: 80 initialDelaySeconds: 3 periodSeconds: 5使用kubectl create -f resource-demo.yaml创建Pod,通过kubectl describe pod resource-demo查看探针状态。
4. 实现多容器Pod的Sidecar模式 🔄
题目要求:创建一个包含两个容器的Podsidecar-demo:主容器使用nginx,sidecar容器使用busybox。Sidecar容器需要每分钟向/usr/share/nginx/html/index.html文件写入当前时间,主容器通过HTTP对外提供该文件内容。
核心考点:多容器Pod、共享存储
解题步骤:
apiVersion: v1 kind: Pod metadata: name: sidecar-demo spec: containers: - name: main-container image: nginx ports: - containerPort: 80 volumeMounts: - name: shared-volume mountPath: /usr/share/nginx/html - name: sidecar-container image: busybox command: ["sh", "-c", "while true; do echo $(date) > /shared/index.html; sleep 60; done"] volumeMounts: - name: shared-volume mountPath: /shared volumes: - name: shared-volume emptyDir: {}创建Pod后,通过kubectl port-forward pod/sidecar-demo 8080:80可在本地访问http://localhost:8080查看时间更新。
5. 创建网络策略限制Pod间通信 🚦
题目要求:在default命名空间创建一个网络策略allow-frontend-to-backend,允许标签为app=frontend的Pod访问标签为app=backend的Pod的8080端口,拒绝其他所有流量。
核心考点:网络策略配置
解题步骤:
apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: allow-frontend-to-backend spec: podSelector: matchLabels: app: backend policyTypes: - Ingress ingress: - from: - podSelector: matchLabels: app: frontend ports: - protocol: TCP port: 8080验证方法:创建带有不同标签的测试Pod,通过kubectl exec测试网络连通性。
高效备考资源推荐 📚
- CKAD官方考试指南
- Excellent CKAD Exercises
- Kubernetes官方文档任务指南
通过以上5个实践题目,你可以全面掌握CKAD考试的核心知识点。建议结合项目中的README.md文档进行系统学习,重点关注"Current Progress"章节的 checklist,确保每个考点都得到充分练习。记住,CKAD考试注重实际操作能力,多动手练习是通过考试的关键!
【免费下载链接】ckad-prep-notesList of resources and notes for passing the Certified Kubernetes Application Developer (CKAD) exam.项目地址: https://gitcode.com/gh_mirrors/ck/ckad-prep-notes
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考