Is it possible to run kubectl within a container within the cluster?

10/22/2019

I have a kubernetes cluster, and I basically have an authenticated api for deploying tasks within the cluster without having kubectl etc set-up locally. I'm aware of the client libraries etc for the Kubernetes api, however they don't seem to support all of the different primatives etc (including some custom ones like Argo). So I just wondered if there was a way I could effectively run $ kubectl apply -f ./file.yml within a container on the cluster?

Obviously I can create a container with kubectl installed, but I just wondered how that could then 'connect' to the Kubernetes controller?

-- Ewan Valentine
docker
istio
kubernetes

3 Answers

3/15/2020

I found that the roffe/kubectl image works well for running a kubectl apply -f to deploy to my cluster. However, you do need to use a ClusterRole and ClusterRoleBinding "attached" to your ServiceAccount, (and the serviceAccount named in your kubectl container), to deploy to any other namespaces.

-- BenDenney
Source: StackOverflow

10/22/2019

Yes, it is possible. refer halyard container. spinnaker is deployed from halyard container.

-- P Ekambaram
Source: StackOverflow

10/22/2019

You can choose from existing ones: https://hub.docker.com/search?q=kubectl&type=image

-- ozlevka
Source: StackOverflow