I’m novice in docker, and i want to practice swarm and after Kubernetes, my question how i can practice given that i have one physical machine ?
The easiest way to have both up and running is to use Docker Desktop.
Enable Kubernetes in Docker Desktop:
Activate Swarm mode (works same for Docker CE and Docker Desktop):
The second easiest or if you have a machine without GUI, you can use Kind. (Kubernetes in Docker)
First, install Docker CE, then:
Install Kind
https://kind.sigs.k8s.io/docs/user/quick-start/#installing-from-release-binaries
Create a cluster
kind create cluster
Check Kubernetes version:
docker container inspect --format '{{ .Config.Image }}' kind-control-plane | cut -d ':' -f2 | cut -d '@' -f1
Download and install a matching kubectl:
Or since this is a Docker forum, let’s use Docker for one more thing, kubectl:
Save this Bash script wherever you like:
#!/usr/bin/env bash
KUBECONFIG="$HOME/.kube/config"
version="$(
docker container inspect --format '{{ .Config.Image }}' kind-control-plane \
| cut -d ':' -f2 \
| cut -d '@' -f1
)"
docker run \
--rm \
-it \
--net host \
--mount "type=bind,source=$HOME,target=$HOME,ro" \
-e "KUBECONFIG=$KUBECONFIG" \
-u $(id -u) \
"bitnami/kubectl:${version:1}" \
"$@"
and run
./kubectl.sh get node
assuming you are in the same folder as the script.
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready control-plane 34m v1.31.0
You could move the shell script to /usr/local/bin/kubectl
without extension to use it simply as kubectl
, but remember that it is running in a container, so when you need to use a manifest file like:
kubectl apply -f deployment.yml
it has to be in your home as only that folder is mounted as read-only.
Don’t use this on a server where other users have access to Docker or use it only if you don’t test anything that requires sharing passwords with Kubernetes that you don’t want other users to see.
This way you can have Docker and activate Swarm as you would normally do, and run Kubernetes in Docker container.
Personally I would not invest time in Swarm, when you want to use k8s anyway. Look at k3s.
We still use Docker Swarm, but its used less and less in business world. I would not learn all the options and mess with its shortcomings if you are going with k8s anyway.
For practice check on docker play which is free, which provides in built docker swarm service.