I am trying to \"pass\" a value from the init container to a container. Since values in a configmap are shared across the namespace, I figured I can use it for this purpose. Her
First of all, kubectl
is a binary. It was downloaded in your machine before you could use the command. But, In your POD, the kubectl binary doesn't exist. So, you can't use kubectl
command from a busybox image.
Furthermore, kubectl uses some credential that is saved in your machine (probably in ~/.kube
path). So, If you try to use kubectl
from inside an image, this will fail because of missing credentials.
For your scenario, I will suggest the same as @ccshih, use volume sharing.
Here is the official doc about volume sharing between init-container
and container
.
The yaml that is used here is ,
apiVersion: v1
kind: Pod
metadata:
name: init-demo
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: workdir
mountPath: /usr/share/nginx/html
# These containers are run during pod initialization
initContainers:
- name: install
image: busybox
command:
- wget
- "-O"
- "/work-dir/index.html"
- http://kubernetes.io
volumeMounts:
- name: workdir
mountPath: "/work-dir"
dnsPolicy: Default
volumes:
- name: workdir
emptyDir: {}
Here init-containers
saves a file in the volume and later the file was available in inside the container. Try the tutorial by yourself for better understanding.