DEV Community

Alex Spinov
Alex Spinov

Posted on

Rancher Has a Free API — Manage Kubernetes Clusters from Your Terminal

Rancher is one of the most popular open-source Kubernetes management platforms. What many developers don't know is that Rancher exposes a full REST API that lets you manage clusters, workloads, and namespaces programmatically.

No paid tier required. No API key signup. Just your Rancher instance and a token.

Why Use the Rancher API?

  • Automate cluster provisioning — spin up new K8s clusters without clicking through the UI
  • Monitor workloads — get real-time status of deployments, pods, and services
  • Manage multi-cluster — control dozens of clusters from a single API endpoint
  • CI/CD integration — deploy apps programmatically in your pipeline

Quick Setup

1. Get Your API Token

In Rancher UI: User Avatar → API & Keys → Add Key

curl -s -X POST https://your-rancher.example.com/v3-public/localProviders/local?action=login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"your-password"}' | jq -r '.token'
Enter fullscreen mode Exit fullscreen mode

2. List All Clusters

RANCHER_URL="https://your-rancher.example.com"
TOKEN="token-xxxxx:your-token-here"

curl -s -H "Authorization: Bearer $TOKEN" \
  "$RANCHER_URL/v3/clusters" | jq '.data[] | {name: .name, state: .state, provider: .provider}'
Enter fullscreen mode Exit fullscreen mode

3. Scale a Deployment

CLUSTER_ID="c-m-xxxxx"
curl -s -X PATCH -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/strategic-merge-patch+json" \
  "$RANCHER_URL/k8s/clusters/$CLUSTER_ID/apis/apps/v1/namespaces/default/deployments/my-app" \
  -d '{"spec":{"replicas":5}}'
Enter fullscreen mode Exit fullscreen mode

Python Example

import requests

RANCHER_URL = "https://your-rancher.example.com"
TOKEN = "token-xxxxx:your-token-here"
headers = {"Authorization": f"Bearer {TOKEN}"}

clusters = requests.get(f"{RANCHER_URL}/v3/clusters", headers=headers).json()
for c in clusters["data"]:
    print(f"Cluster: {c['name']} | State: {c['state']} | Nodes: {c['nodeCount']}")
Enter fullscreen mode Exit fullscreen mode

Key Endpoints

Use Case Endpoint Method
List clusters /v3/clusters GET
Create cluster /v3/clusters POST
List projects /v3/projects GET
Scale deployment /k8s/clusters/{id}/apis/apps/v1/... PATCH
Cluster events /v3/clusters/{id}/clusterevents GET

Tips

  • No rate limits on self-hosted Rancher
  • Token-based auth — no OAuth complexity
  • Full Kubernetes API proxy
  • WebSocket support for real-time events

Need custom data extraction or scraping solution? I build production-grade scrapers for any website. Email: Spinov001@gmail.com | My Apify Actors

Top comments (0)