Rancher Instalaation for Kubernetes Management

Rancher is a comprehensive Kubernetes management platform providing centralized clúster management, workload implementación, monitoreo, and administration capabilities. Esta guía cubre Docker and Helm installation methods, importing and provisioning clústers, working with catalogs, integrated monitoreo, and managing multiple Kubernetes clústers from a single pane of glass on your VPS and baremetal infrastructure.

Tabla de contenidos

Rancher Overview

What is Rancher?

Rancher es código abierto multi-clúster Kubernetes management platform:

  • Single control pane for multiple clústers
  • Deploy applications across clústers
  • Integrated monitoreo and registro
  • RBAC and multi-tenancy
  • Complete Kubernetes management UI

Arquitectura

Rancher Management Cluster
├── API Server
├── Database (etcd)
├── Authentication (local/external)
└── Monitoring Stack
        ↓
    Remote Clusters
    ├── User Clusters
    ├── Imported Clusters
    └── Provisioned Clusters

Key Features

  • Multi-Cluster Management: Manage unlimited clústers
  • Workload Management: Deploy apps easily via UI
  • Catalog: Pre-built application templates
  • Monitoring: Integrated Prometheus and Grafana
  • Logging: Aggregated clúster logs
  • RBAC: Global and clúster-level access control
  • Projects: Logical grouping of espacio de nombress

Instalación Methods

Docker Instalaation

Quick setup using Docker:

# Create directory for persistent data
mkdir -p /opt/rancher

# Run Rancher in Docker
docker run -d \
  --restart=unless-stopped \
  -p 80:80 -p 443:443 \
  -v /opt/rancher:/var/lib/rancher \
  --name rancher \
  rancher/rancher:v2.7.0

# Get bootstrap password
docker logs rancher 2>&1 | grep "Bootstrap Password:"

# Access: https://localhost

Helm Instalaation on Kubernetes

Instala Rancher management clúster using Helm:

# Add Helm repository
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
helm repo update

# Create namespace
kubectl create namespace cattle-system

# Create certificate issuer (using cert-manager)
kubectl apply -f - << 'EOF'
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
  name: rancher-selfsigned
  namespace: cattle-system
spec:
  selfSigned: {}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: tls-rancher-ingress
  namespace: cattle-system
spec:
  secretName: tls-rancher-ingress
  commonName: rancher.example.com
  issuerRef:
    name: rancher-selfsigned
    kind: Issuer
EOF

# Install Rancher
helm install rancher rancher-stable/rancher \
  --namespace cattle-system \
  --set hostname=rancher.example.com \
  --set bootstrapPassword=InitialPassword123 \
  --set ingress.tls.source=rancher \
  --set certmanager.enabled=false

# Wait for deployment
kubectl rollout status deployment/rancher -n cattle-system

Production Helm Instalaation

With Let's Encrypt certificates:

# Install cert-manager first
helm repo add jetstack https://charts.jetstack.io
helm repo update

helm install cert-manager jetstack/cert-manager \
  -n cert-manager \
  --create-namespace \
  --set installCRDs=true

# Install Rancher with Let's Encrypt
helm install rancher rancher-stable/rancher \
  --namespace cattle-system \
  --create-namespace \
  --set hostname=rancher.example.com \
  --set bootstrapPassword=StrongPassword123 \
  --set ingress.tls.source=letsEncrypt \
  --set [email protected] \
  --set letsEncrypt.environment=production

Verifica Instalaation

# Check Rancher pods
kubectl get pods -n cattle-system

# Get Rancher service
kubectl get svc -n cattle-system -l app=rancher

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

Cluster Import and Management

Importing Existing Clusters

Import a clúster into Rancher management:

  1. In Rancher UI: Clusters → Import Existing
  2. Select clúster type (generic Kubernetes)
  3. Copy provided kubectl command
  4. Run on target clúster:
# Run provided command from Rancher UI
kubectl apply -f https://rancher.example.com/v3/import/xxxxx.yaml

Or import via kubectl directly:

# Execute on cluster to import
curl --insecure -sfL https://rancher.example.com/v3/import/xxxxx.yaml | kubectl apply -f -

# Verify agent installation
kubectl get pods -n cattle-system

Managing Imported Clusters

Once imported:

  • View clúster nodes and resources
  • Deploy applications
  • Manage workloads
  • Monitor clúster health
  • Configura reding

Cluster API Credentials

# Get cluster credentials
kubectl config view --flatten

# Export kubeconfig for imported cluster
# Via Rancher UI: Clusters → Download KubeConfig

Workload Deployment

Deploying via Rancher UI

  1. Select Cluster → Default Project
  2. Workloads → Deployments
  3. Create Deployment
  4. Configura:
    • Container imagen
    • Ports and environment
    • Resources and replicas
    • Storage volumens
  5. Create

Deploying via kubectl

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
      - name: web
        image: web:1.0
        ports:
        - containerPort: 8080
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 500m
            memory: 512Mi

Deploy:

kubectl apply -f deployment.yaml

Managing Services and Ingress

Create servicio:

# Via Rancher UI: Workloads → Services
# Or kubectl
kubectl expose deployment web-app --port=80 --target-port=8080

Create ingreso:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-app
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  tls:
  - hosts:
    - web.example.com
    secretName: web-tls
  rules:
  - host: web.example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web-app
            port:
              number: 80

Catalogs and Templates

Using Built-in Catalogs

Rancher includes Helm catalogs for easy implementacións:

  1. Apps & Marketplace → Instalaed Apps
  2. Create
  3. Select app from catalog (WordPress, MySQL, etc.)
  4. Configura and deploy

Adding Custom Catalogs

Add custom Helm chart repositories:

# Via Rancher UI:
# Apps & Marketplace → Repositories
# Add Helm Repository
# Name: my-charts
# URL: https://charts.example.com

# Or via kubectl/API
kubectl apply -f - << 'EOF'
apiVersion: catalog.cattle.io/v1
kind: ClusterRepo
metadata:
  name: my-charts
spec:
  url: https://charts.example.com
  gitRepo: https://github.com/example/charts.git
  gitBranch: main
EOF

Creating Application Templates

Create reusable templates:

apiVersion: catalog.cattle.io/v1
kind: AppTemplate
metadata:
  name: my-app-template
  namespace: cattle-system
spec:
  chart:
    name: my-app
    repo: my-charts
    version: 1.0.0
  questions:
  - variable: replicas
    label: Number of Replicas
    type: integer
    default: 3
  - variable: imageTag
    label: Image Tag
    type: string
    default: latest

Supervisión Integration

Enabling Monitoring

# Via Rancher UI: Monitoring
# Or install via Helm
helm install prometheus-community/kube-prometheus-stack \
  -n monitoring \
  --create-namespace

Viewing Metrics

  1. Cluster → Monitoring
  2. Dashboard shows:
    • Cluster metrics
    • Node resources
    • Pod resource usage

Creating Custom Dashboards

In Grafana (integrated with Rancher):

  1. Dashboards → New Dashboard
  2. Add panels with Prometheus queries
  3. Visualize clúster metrics

Cluster Provisioning

Provisioning New Clusters

Create managed clústers via Rancher:

  1. Clusters → Create
  2. Select clúster type (RKE2, K3s, etc.)
  3. Configura:
    • Cluster name
    • Kubernetes version
    • Node count and specs
  4. Provision

RKE2 Cluster Provisioning

# Rancher automatically provisions via RKE2
# View cluster creation status in Rancher UI
# Logs available at: /var/lib/rancher/rke2/agent/logs/

Practical Examples

Ejemplo: Multi-Cluster Setup

#!/bin/bash

echo "=== Installing Rancher Management Cluster ==="

# Create management cluster
k3s_version="v1.27.0"
curl -sfL https://get.k3s.io | K3S_KUBECONFIG_MODE=644 sh -

# Install cert-manager
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.12.0/cert-manager.yaml

# Install Rancher
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
helm repo update

helm install rancher rancher-stable/rancher \
  -n cattle-system \
  --create-namespace \
  --set hostname=rancher.example.com \
  --set bootstrapPassword=ManagementPassword123 \
  --set ingress.tls.source=letsEncrypt \
  --set [email protected]

echo "=== Rancher Installed ==="
echo "Access at: https://rancher.example.com"

# Import existing clusters
echo "=== Ready to import clusters ==="
echo "In Rancher UI: Clusters → Import Existing"

Ejemplo: Project and RBAC Setup

---
# Project for team
apiVersion: management.cattle.io/v3
kind: Project
metadata:
  name: backend-team
spec:
  displayName: "Backend Team"
  description: "Backend service development"
---
# Cluster member role
apiVersion: management.cattle.io/v3
kind: ClusterRoleTemplateBinding
metadata:
  name: backend-team-member
spec:
  clusterName: local
  roleTemplateName: admin
  userPrincipalName: team-members-group
---
# Project namespace
apiVersion: v1
kind: Namespace
metadata:
  name: backend
  labels:
    cattle.io/project: backend-team

Conclusión

Rancher provides a comprehensive platform for managing Kubernetes across your organization. By centralizing clúster management, providing intuitive UI for workload implementación, integrating monitoreo and registro, and supporting multiple clústers from a single pane of glass, Rancher dramatically simplifies Kubernetes operations. Start with importing existing clústers, progress to managing applications through the UI, and leverage catalogs for rapid implementacións. Rancher's flexibility supports both small implementacións on VPS and large-scale multi-clúster infrastructure on baremetal servers, making it an excellent choice for organizations of any size managing Kubernetes infrastructure.