LAB-14:监控Pod日志
LAB 概述
监控 pod foobar 的日志并提取错误的 unable-access-website 相对于的日志写入到 /opt/KUTR00101/foobar
LAB 预配
# 编写 pod 为 foobar 的资源清单 user1@k8s-master:~/cka-2022-05-01/14$ cat foobar-pod.yaml apiVersion: v1 kind: Pod metadata: name: foobar labels: app: foobar spec: containers: - name: nginx image: nginx:1.18.0 imagePullPolicy: IfNotPresent ports: - containerPort: 80 # 创建 pod 资源 user1@k8s-master:~/cka-2022-05-01/14$ kubectl apply -f foobar-pod.yaml pod/foobar created # 查看 pod user1@k8s-master:~$ kubectl get pod foobar NAME READY STATUS RESTARTS AGE foobar 1/1 Running 0 11s # 创建 /opt/KUTR00101 user1@k8s-master:~$ sudo mkdir /opt/KUTR00101
LAB 答案
# 切换 content $ kubectl config use-context k8s # 日志导入到文件 $ sudo sh -c 'kubectl logs foobar | grep unable-to-access-website > /opt/KUTR00101/foobar' # 实验环境应该没有这个日志 “unable-to-access-website”,可以发送全部日志,这样可以查看 foobar 文件 $ sudo sh -c 'kubectl logs foobar > /opt/KUTR00101/foobar'
LAB 验证
# 查看日志 $ cat /opt/KUTR00101/foobar
参考资料
- https://kubernetes.io/zh/docs/concepts/cluster-administration/logging/