Rancher installation and importing of existing cluster
Prerequisites: Kubernetes K3S version v1.21.4+k3s1
We will be installing rancher which is a Kubernetes Management Tool that provides UI.
Step 1: Use the Vagrant file to scale up the vagrant machines and use the command vagrant up.
Step 2: Use SSH to login to the vagrant Rancher machine and install docker.
Step 3: Use the docker command to run rancher v2.5.9.
sudo docker run -d — privileged — restart=unless-stopped -p 85:80 -p 7443:443 -v rancher-data:/var/lib/rancher — name=rancher -e CATTLE_SERVER_URL=https://192.168.56.30 -e CATTLE_HOST_LABELS=’hostname=192.168.56.30' -e CATTLE_BOOTSTRAP_PASSWORD=admin@123 rancher/rancher:v2.5.9
Note: Since rancher is a UI interface and operates in port 80 & 443, I’ve used port forwarding since other services in my local machine might be using port 80 or 443 like Jenkins. Also, in the command various flags are used.
Step 4: Verify docker standalone container is running.
Step 5: Your rancher UI looks something like this.
Step 6: Now, add the existing K3S cluster in the rancher. For that you need to go to the Global panel in the rancher and click on ‘Add Cluster’ and click on ‘Other Cluster’.
Step 7: Name the cluster and create it.
Step 8: Here, you will be prompted to the kubectl command which you will use to add the cluster.
Step 9: Use the third option.
Step 10: Analyse the yaml file first. For that use the first half of the command.
curl — insecure -sfL https://192.168.56.30:7443/v3/import/key456@#$key.yaml | kubectl apply -f -
Note: Don’t forget to add the port 7443 after the IP since we have used port forwarding.
Step 11: Copy the YAML file into a new file using the command cat > cluster.yaml.
Step 12: Deploy the yaml file using the command kubectl apply -f cluster.yaml.
Step 13: You will see a cattle cluster agent pod and deployment running. This means you have imported your existing cluster into rancher.
Step 14: Check the rancher machine.
Step 15: Go to the cluster and analyze that a hello-world nginx image application is deployed and is also visible in the rancher machine now.
Step 16: Further explore the cluster by checking nodes.
You can deploy applications now using rancher. Explore it!!
Thank You
The END
Compiled by: Suryansh Mathema
Date: 30/05/2023