I want to run \'kubectl\' commands in the container, so i want to install kubectl in the container, through while building the Docker image. Any help is appreciated!
You just need to map kubectl
(e.g. /usr/local/bin/kubectl
) binary file and kubeconfig
(e.g. /root/.kube/config
) into your container.
For example (yaml file for Deployment):
containers:
- image: container-image-name
name: container-name
volumeMounts:
- name: kubectl-binary
mountPath: /usr/local/bin/kubectl
readOnly: true
- name: kubectl-config
mountPath: /root/.kube/config
readOnly: true
volumes:
- name: kubectl-binary
hostPath:
path: /usr/local/bin/kubectl
- name: kubectl-config
hostPath:
path: /root/.kube/config
P.S.
use the following command to download kubectl
binary file on each node, and copy /root/.kube/config
to each node:
$ curl -L https://dl.k8s.io/v1.10.6/bin/linux/amd64/kubectl -o /usr/local/bin/kubectl