-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
title: "Kubernetes while redirection into a file
- Loading branch information
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
--- | ||
title: "Kubernetes while redirection into a file " | ||
date: 2023-11-20T20:10:00+08:00 | ||
categories: | ||
- tech | ||
tags: | ||
- kubelet | ||
- pods | ||
- command | ||
- args | ||
- redirection | ||
- shell | ||
- heredoc | ||
--- | ||
|
||
My 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. https://stackoverflow.com/questions/52711337/kubernetes-redirecting-echo-into-a-file-not-creating-file[This one] from stackoverfow gave me a clue how to resolve my issue. | ||
|
||
The lessons I learnt from this one: | ||
|
||
. https://stackoverflow.com/questions/27920806/how-to-avoid-heredoc-expanding-variables[Avoid brace expansion in heredoc] | ||
|
||
. https://stackoverflow.com/questions/52711337/kubernetes-redirecting-echo-into-a-file-not-creating-file[args to redirect to a file] | ||
|
||
|
||
My final solution is below: | ||
|
||
[source, bash] | ||
---- | ||
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 | ||
---- |