Home > OS >  How do I run k3s within docker using the official rancher docker image
How do I run k3s within docker using the official rancher docker image

Time:03-21

I want to start a server and a client using docker run rancher/k3s:latest server and docker run -e K3S_TOKEN=xyz -e K3S_URL=https://<server_container_name>:6443 rancher/k3s:latest agent

But for some reason, the server and the client aren't able to communicate with each other even if I deploy it on a separate network. Any suggestions as to what can be done?

CodePudding user response:

Starting your first server, you would want to expose ports. Eg:

docker run -p 6443:6443 ranger/k3s:latest server

Then, make sure the other container can resolve the FQDN for your K3S_URL, sending this to the host address where your initial server was started on. Eg:

docker run --add-host <server_name>:<ip-address> \
    -e K3S_TOKEN=xyz -e K3S_URL=https://<server_name>:6443 \
    rancher/k3s:latest agent

Also note: in my case, I also had to add the --privileged docker option, and some --snapshotter native option

docker run --privileged -p 6443:6443 rancher/k3s:latest server --snapshotter native
docker run --privileged -e K3S_TOKEN=xxx --add-host=adcbd2a250ff:10.42.42.127 -e K3S_URL=https://adcbd2a250ff:6443 rancher/k3s:latest agent --snapshotter native
  • Related