Kubernetes while redirection into a file
- 1 minutes read - 168 wordsMy first attemp to resolve "Kubernetes Time Check Pod" in https://engineer.kodekloud.com is not successful. The exercise doesn’t allow to open an editor to edit a yaml file. I had to resort to cat. I attempted several times to resolve it on my local cluster, still no luck even I tried different combination such as command, args,string in string, avoiding expansion. This one from stackoverfow gave me a clue how to resolve my issue.
The lessons I learnt from this one:
My final solution is below:
cat <<'EOF' | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: time-check
name: time-check
namespace: datacenter
spec:
volumes:
- name: log-volume
emptyDir: {}
containers:
- image: busybox:latest
name: time-check
env:
- name: TIME_FREQ
valueFrom:
configMapKeyRef:
name: time-config
key: TIME_FREQ
command: ["/bin/sh"]
args: ["-c", "while true; do date; sleep $(TIME_FREQ); done > /opt/data/time/time-check.log"]
resources: {}
volumeMounts:
- name: log-volume
mountPath: /opt/data/time
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {}
EOF