← Back to Blog

πŸš€ How to Set Up Rancher in GitHub Codespaces and Use Plugins

πŸš€ How to Set Up Rancher in GitHub Codespaces and Use Plugins If you’re looking to manage Kubernetes with Rancher using GitHub Codespaces , you’re in the right place!

πŸš€ How to Set Up Rancher in GitHub Codespaces and Use Plugins

If you’re looking to manage Kubernetes with Rancher using GitHub Codespaces, you’re in the right place! πŸš€ This step-by-step guide will walk you through setting up Rancher inside your GitHub Codespace environment and using plugins like Prometheus for monitoring and Longhorn for storage. Let's get started! πŸ’‘


Prerequisites πŸ› οΈ

Before we dive into the setup, make sure you have the following:

  • βœ… GitHub account and GitHub Codespaces enabled.

  • βœ… Docker pre-installed in your Codespace (Docker comes pre-installed in GitHub Codespaces).

  • βœ… A Kubernetes cluster, which you can provision using k3d (Kubernetes in Docker).

  • βœ… Helm, which we’ll use to install Rancher on Kubernetes.


Step 1: Set Up Kubernetes with k3d in Codespaces βš™οΈ

The first step is to create a Kubernetes cluster inside your Codespace using k3d.

1. Open Your Codespace πŸš€

Launch your Codespace environment from a GitHub repository or create a new one.

2. Install k3d for Kubernetes 🚒

Next, we need to install k3d, which lets us run Kubernetes clusters within Docker. Run the following command to install it:

curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash

3. Create a Kubernetes Cluster 🌐

Once k3d is installed, create your Kubernetes cluster using:

k3d cluster create rancher-cluster --servers 1 --agents 2

This command will create a Kubernetes cluster with 1 server node and 2 agent nodes.

πŸ’‘ Tip: Adjust the number of agents and servers based on your needs.

4. Verify the Cluster 🧐

Ensure your cluster is up and running:

kubectl get nodes

You should see your nodes listed here.


Step 2: Install Rancher on Kubernetes using Helm πŸ› οΈ

Now that we have Kubernetes running, let’s install Rancher on the cluster using Helm.

1. Add Rancher Helm Chart Repository πŸ“¦

Before installing Rancher, we need to add the Rancher Helm chart repository:

helm repo add rancher-latest https://releases.rancher.com/server-charts/latest

2. Create a Namespace for Rancher πŸ“‚

Let’s create a dedicated namespace for Rancher:

kubectl create namespace cattle-system

3. Install Cert-Manager for SSL/TLS Management πŸ”’

Rancher needs Cert-Manager to handle SSL certificates. Install it using Helm:

helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.5.3 --set installCRDs=true

4. Install Rancher πŸ„

Finally, we’re ready to install Rancher! Run this command to deploy it with a self-signed certificate:

helm install rancher rancher-latest/rancher --namespace cattle-system --set hostname=rancher.local --set replicas=1 --set ingress.tls.source=rancher

πŸ’‘ If you have a custom domain and certificate, replace --set ingress.tls.source=rancher with your certificate source.

5. Verify Rancher Deployment βœ…

Check that Rancher is deployed correctly with this command:

kubectl -n cattle-system rollout status deploy/rancher


Step 3: Access Rancher UI 🌐

Once Rancher is installed, you can access its UI by forwarding the service from your Codespace to your browser.

1. Port Forward Rancher πŸ› οΈ

Use kubectl to forward Rancher’s service:

kubectl -n cattle-system port-forward svc/rancher 8443:443

Now open https://localhost:8443 in your browser to access Rancher’s UI.


Step 4: Using Rancher Plugins πŸŽ›οΈ

Rancher supports several plugins, which you can install via Helm. Here’s how to get started with some essential ones.

1. Install Rancher CLI πŸ’»

First, install the Rancher CLI to manage Rancher from the terminal:

curl -L https://github.com/rancher/cli/releases/download/v2.4.13/rancher-linux-amd64-v2.4.13.tar.gz | tar xz
mv rancher-v2.4.13/rancher /usr/local/bin/rancher

2. Authenticate with Rancher πŸ›‘οΈ

Log in to Rancher using the CLI:

rancher login https://localhost:8443 --token

Replace <RANCHER_API_TOKEN> with the token you generate from the Rancher UI.


Installing Plugins via Rancher πŸ› οΈ

Rancher has an extensive app catalog for monitoring, storage, and more. Let’s install a few popular plugins.

Example 1: Install Monitoring Plugin πŸ“Š

Prometheus and Grafana provide monitoring for your Kubernetes cluster. Install it using Helm:

kubectl create namespace cattle-monitoring-system
helm install rancher-monitoring rancher-monitoring/rancher-monitoring --namespace cattle-monitoring-system

Example 2: Install Longhorn for Storage πŸ’Ύ

Longhorn provides distributed block storage in Kubernetes. Install it via Helm:

helm repo add longhorn https://charts.longhorn.io
helm install longhorn longhorn/longhorn --namespace longhorn-system

πŸ’‘ Check out the Rancher UI to explore even more plugins!


Additional Considerations πŸ€”

  • Persistent Storage: If you need persistent storage for your workloads, Longhorn is a great solution.

  • GitHub Actions: Automate your Rancher deployments with GitHub Actions for CI/CD workflows.

By following these steps, you’ll have Rancher running smoothly in your GitHub Codespaces environment, along with plugins like Prometheus, Grafana, and Longhorn.


πŸ’‘ Need More Help?
Feel free to reach out to me on any of these platforms for assistance!

πŸ”— Connect with me:

Happy Coding! πŸ’»πŸŽ‰


Imported from rifaterdemsahin.com Β· 2024