I have a running minikube cluster. I can easily connect to it and apply changes using kubectl. But I want to run kubectl from a docker container. Here is the Dockerfile:
FROM alpine:latest
RUN apk --no-cache add curl
# Install and configure kubectl
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
RUN mkdir -p ~/.local/bin/kubectl
RUN mv ./kubectl ~/.local/bin/kubectl
RUN chmod +x ~/.local/bin/kubectl/ -R
It's basically a simple alpine image with kubectl installed.
How can I connect to my minikube cluster from this container?
I had to copy
~/.kubeand~/.minikubefolders into the image. This is the new Dockerfile:You can use the image like this:
ATTENTION
The
.kube/configfile is created for the host system. So you need to change some paths in.kube/configfile to point to the.minikubefolder in the container.ALSO NOTE THAT
~/.minikubeand~/.kubeare huge folders. Adding them to your docker build context could make your builds really slow.You might want to mount volumes for that purpose.