π 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=rancherwith 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