Kubernetes in Docker container with kubectl and SSH server
547
Kubernetes-In-Docker is an image that allows running Kubernetes cluster in a docker container
The main differences of this image from the official kind image are:
kubectl can be executed from the docker container,This image might come in handy in complex docker compose environments where kubectl commands are needed. Connect to the k8s container through SSH and and execute kubectl commands.
The Dockerfile can be found on GitHub
mkdir example
cd example
docker-compose.yml:curl -LO https://raw.githubusercontent.com/neshkeev/containers/master/k8s/example/single-node/docker-compose.yml
docker compose up -d
docker compose logs k8s -f
hello-world pod from the k8s container:docker compose exec -it k8s kubectl run hello-world --image=hello-world --image-pull-policy=Always
docker compose exec -it k8s kubectl get pods
docker compose exec -it k8s kubectl describe pod/hello-world
docker compose exec -it k8s kubectl logs pod/hello-world
docker compose exec -it k8s kubectl delete pod/hello-world
docker compose exec -it k8s kubectl get pods
hello-world pod from the k8s container:docker compose exec -it k8s ssh root@localhost 'kubectl run hello-world --image=hello-world --image-pull-policy=Always'
docker compose exec -it k8s ssh root@localhost 'kubectl get pods'
docker compose exec -it k8s ssh root@localhost 'kubectl describe pod/hello-world'
docker compose exec -it k8s ssh root@localhost 'kubectl logs pod/hello-world'
docker compose exec -it k8s ssh root@localhost 'kubectl delete pod/hello-world'
docker compose exec -it k8s ssh root@localhost 'kubectl get pods'
docker compose exec -it k8s kind delete cluster
docker compose down
In order to start a multi-cluster k8s setup execute the following commands:
mkdir -p example/conf
cd example
docker-compose.yml:curl -LO https://raw.githubusercontent.com/neshkeev/containers/master/k8s/example/multi-node/docker-compose.yml
config.yml kind (Kubernetes-In-Docker) config file:curl -Lo conf/config.yml https://raw.githubusercontent.com/neshkeev/containers/master/k8s/example/multi-node/conf/config.yml
docker compose up -d
docker compose logs k8s -f
docker compose exec -it k8s kubectl get nodes
docker compose exec -it k8s kind delete cluster
docker compose down
This docker images spins kind, so all the kind's configuration can be applied.
Please keep in mind that you need to:
config.yaml file into the k8s container,K8S_CONFIG_FILE environment variable to the mounted file on the container's file system.Setting the K8S_CONFIG_FILE environment variable can be omitted, if you mount the config file at the /etc/kubernetes/config.yml mount point.
Issue: a k8s container's SSH server crushes on restart
Solution: remove the container and start it again
... no such hostIssue: When I execute kubectl get nodes or another commands I get:
$ kubectl get nodes
E1129 19:26:09.617992 758 memcache.go:265] couldn't get current server API group list: Get "https://kind-control-plane:6443/api?timeout=32s": dial tcp: lookup kind-control-plane on 127.0.0.11:53: no such host
Solution: Please make sure the network of the k8s container is named kind
Content type
Image
Digest
sha256:473e48bf2…
Size
261.8 MB
Last updated
over 2 years ago
docker pull neshkeev/k8s