Skip to content

Instantly share code, notes, and snippets.

@Shaked
Last active August 31, 2021 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shaked/389d6ca91cd27978cd1a6ce31549f55d to your computer and use it in GitHub Desktop.
Save Shaked/389d6ca91cd27978cd1a6ce31549f55d to your computer and use it in GitHub Desktop.
Rancher server with multipass and k3s multi node environment on macOS
  1. Create a VM for rancher server:
multipass launch --name rancher-server --cpus 4 --mem 4g --disk 20g
multipass exec rancher-server -- bash -c "curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -"
multipass exec rancher-server sudo cat /etc/rancher/k3s/k3s.yaml > ~/.kube/rancher-server.yaml
RANCHER_SERVER_IP=$(multipass info k3s | grep IPv4 | awk '{print $2}')
sed -i '' "s/127.0.0.1/${RANCHER_SERVER_IP}/"  ~/.kube/rancher-server.yaml
kubie ctx default
  1. brew install helm@3
  2. Install cert manager, make sure to get the latest https://cert-manager.io/docs/installation/helm/
			  cert-manager jetstack/cert-manager \
			  --namespace cert-manager \
			  --create-namespace \
			  --version v1.5.3 \
			  --set installCRDs=true
  1. kubectl create namespace cattle-system
  2. Install rancher
helm install rancher rancher-latest/rancher \
			  --namespace cattle-system \
			  --set hostname=rancher.localdev
  1. Wait until the pods under cattle-system namespace are running and finished loading the server. This might take few minutes
  2. Create a VM for k3s client:
multipass launch --name k3s-client --cpus 4 --mem 4g --disk 20g
multipass exec k3s-client -- bash -c "curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE="644" sh -"
  1. Install Rancher's generated YAMLs on the client:
# We are using the Host header as it's not possible to edit /etc/hosts on multipass (and maybe not needed) 
curl --insecure -H "Host: rancher.localdev" -sfL https://$RANCHER_SERVER_IP/v3/import/...-m-j7wlcfmc.yaml | kubectl apply -f -
  1. Run multipass exec k3s-client -- bash -c "kubectl get cm coredns -n kube-system -o yaml" and look for hosts /etc/coredns/NodeHosts {
  2. Add a new row directly after with the IP and the host, with 192.168.64.4 rancher.localdev it should look like:
  Corefile: |
    .:53 {
......
        hosts /etc/coredns/NodeHosts {
          192.168.64.4 rancher.localdev
          ttl 60
          reload 15s
          fallthrough
        }
....
    }
  1. Restart rancher agent: multipass exec k3s-client -- bash -c "kubectl -n cattle-system rollout restart deployment cattle-cluster-agent"
  2. Wait until it's up. It should work now.

This has been tested with:

Rancher 2.6.0
$ k3s -v 
k3s version v1.21.4+k3s1 (3e250fdb)
go version go1.16.6
$ multipass version                                                                                                                                                                      [Wed Sep  1 01:56:05 2021] 2 ↵
multipass  1.7.0+mac
multipassd 1.7.0+mac

References

https://jyeee.medium.com/kubernetes-on-your-macos-laptop-with-multipass-k3s-and-rancher-2-4-6e9cbf013f58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment