我正在尝试将边车容器添加到现有 pod(webapp-1)以保存日志。但是,创建 pod 后出现错误。吊舱正在崩溃,状态更改为错误..
对于以下问题,我添加了 yaml 文件。请让我知道这是否可以。
在运行的pod logging-pod 中添加一个side car 容器,带有blow 规范
sidecar 容器镜像是busybox,容器写入日志如下
tail -n+1 /var/log/k8slog/application.log
容器与挂载到的应用容器共享卷日志
目录 /var/log/k8slog
不要更改应用程序容器并验证日志是否正确写入文件
这是yaml文件。我不明白我在哪里犯了错误。
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2021-10-25T07:54:07Z"
labels:
name: webapp-1
name: webapp-1
namespace: default
resourceVersion: "3241"
uid: 8cc29748-7879-4726-ac60-497ee41f7bd6
spec:
containers:
- image: kodekloud/event-simulator
imagePullPolicy: Always
name: simple-webapp
- /bin/sh
- -c
- >
i=0;
while true;
do
echo "$i: $(date)" >> /var/log/k8slog/application.log
echo "$(date) INFO $i" >>;
i=$((i+1));
sleep 1;
done
volumeMounts:
- name: varlog
mountPath: /var/log
- name: count-log-1
image: busybox
args: [/bin/sh, -c, 'tail -n+1 /var/log/k8slog/application.log']
volumeMounts:
- name: varlog
mountPath: /var/log
ports:
- containerPort: 8080
protocol: TCP
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /var/run/secrets/kubernetes.io/serviceaccount
name: default-token-fgstk
readOnly: true
dnsPolicy: ClusterFirst
enableServiceLinks: true
nodeName: controlplane
preemptionPolicy: PreemptLowerPriority
priority: 0
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: default
serviceAccountName: default
terminationGracePeriodSeconds: 30
tolerations:
- effect: NoExecute
key: node.kubernetes.io/not-ready
operator: Exists
tolerationSeconds: 300
- effect: NoExecute
key: node.kubernetes.io/unreachable
operator: Exists
tolerationSeconds: 300
volumes:
- name: varlog
mountPath: /var/log
- name: default-token-fgstk
secret:
defaultMode: 420
secretName: default-token-fgstk
status:
conditions:
- lastProbeTime: null
lastTransitionTime: "2021-10-25T07:54:07Z"
status: "True"
type: Initialized
- lastProbeTime: null