【CKA模拟题】如何优雅地融合Pod日志与ConfigMap

本文涉及的产品
Serverless 应用引擎 SAE,800核*时 1600GiB*时
容器镜像服务 ACR,镜像仓库100个 不限时长
EMR Serverless StarRocks,5000CU*H 48000GB*H
简介: 【CKA模拟题】如何优雅地融合Pod日志与ConfigMap

题干

For this question, please set this context (In exam, diff cluster name)

kubectl config use-context kubernetes-admin@kubernetes


Create a Kubernetes Pod configuration to facilitate real-time monitoring of a log file. Specifically, you need to set up a Pod named alpine-pod-pod that runs an Alpine Linux container.

Requirements:

  • Name the Pod alpine-pod-pod .
  • Use alpine:latest image
  • Configure the container to execute the tail -f /config/log.txt command using /bin/sh to continuously monitor and display the contents of a log file.
  • Set up a volume named config-volume that maps to a ConfigMap named log-configmap , this log-configmap already available.
  • Ensure the Pod has a restart policy of Never .

创建一个Kubernetes Pod配置,以便于实时监控日志文件。具体来说,您需要设置一个名为alpine-pod-pod的Pod,它运行一个Alpine Linux容器。

要求:

  • 将Pod命名为alpine-pod-pod。
  • 使用alpine:latest映像
  • 配置容器,使用/bin/sh执行尾部-f /config/log.txt命令,以持续监控和显示日志文件的内容。
  • 设置一个名为config-volume的卷,该卷映射到名为log-configmap的ConfigMap,该log-configmap已经可用。
  • 确保Pod的重启策略为Never 。

解题思路

  1. 切换K8S集群环境
kubectl config use-context kubernetes-admin@kubernetes
  1. 按照要求编写Pod的资源清单,如下
apiVersion: v1
kind: Pod
metadata:
  name: alpine-pod-pod
spec:
  containers:
  - name: alpine-container
    image: alpine:latest
    command: ["/bin/sh", "-c"]
    args: ["tail -f /config/log.txt"]
    volumeMounts:
    - name: config-volume
      mountPath: /config
  restartPolicy: Never
  volumes:
  - name: config-volume
    configMap:
      name: log-configmap

configMap不需要创建已经存在,直接使用即可

  1. 提交资源清单
controlplane $ k apply  -f alpine-pod-pod.yaml 
pod/alpine-pod-pod created
  1. 验证结果
controlplane $ k get pod
NAME             READY   STATUS    RESTARTS   AGE
alpine-pod-pod   1/1     Running   0          3s
controlplane $ k logs alpine-pod-pod 
<LOG DATA>
相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
目录
相关文章
|
2月前
|
存储 Kubernetes 容器
在k8S中,如何查看一个Pod最近20分钟日志?
在k8S中,如何查看一个Pod最近20分钟日志?
|
2月前
|
存储 Kubernetes 网络安全
[k8s]使用nfs挂载pod的应用日志文件
[k8s]使用nfs挂载pod的应用日志文件
100 1
|
2月前
|
Kubernetes 容器 Perl
在K8S中,如何查看Pod中某个容器日志?
在K8S中,如何查看Pod中某个容器日志?
|
2月前
|
Kubernetes 容器 Perl
在k8S中,如何查看Pod中上一个挂掉的容器日志?
在k8S中,如何查看Pod中上一个挂掉的容器日志?
|
5月前
|
Kubernetes Perl 容器
【CKA模拟题】过滤Pod错误日志
【CKA模拟题】过滤Pod错误日志
40 1
|
2月前
|
Kubernetes Ubuntu Windows
【Azure K8S | AKS】分享从AKS集群的Node中查看日志的方法(/var/log)
【Azure K8S | AKS】分享从AKS集群的Node中查看日志的方法(/var/log)
|
23天前
|
Java
日志框架log4j打印异常堆栈信息携带traceId,方便接口异常排查
日常项目运行日志,异常栈打印是不带traceId,导致排查问题查找异常栈很麻烦。
|
1月前
|
存储 监控 数据可视化
SLS 虽然不是直接使用 OSS 作为底层存储,但它凭借自身独特的存储架构和功能,为用户提供了一种专业、高效的日志服务解决方案。
【9月更文挑战第2天】SLS 虽然不是直接使用 OSS 作为底层存储,但它凭借自身独特的存储架构和功能,为用户提供了一种专业、高效的日志服务解决方案。
66 9
|
2月前
|
开发框架 .NET Docker
【Azure 应用服务】App Service .NET Core项目在Program.cs中自定义添加的logger.LogInformation,部署到App Service上后日志不显示Log Stream中的问题
【Azure 应用服务】App Service .NET Core项目在Program.cs中自定义添加的logger.LogInformation,部署到App Service上后日志不显示Log Stream中的问题
|
2月前
|
存储 监控 安全
下一篇
无影云桌面