How to install kubectl in kubernetes container through docker image

后端 未结 4 1842
情书的邮戳
情书的邮戳 2021-02-06 10:36

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!

4条回答
  •  耶瑟儿~
    2021-02-06 11:06

    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
    

提交回复
热议问题