Rancher

DevOpsコンテナKubernetesマルチクラスター管理プラットフォームSUSEオーケストレーション

DevOpsツール

Rancher

概要

Rancherは、マルチクラスターKubernetes管理プラットフォームです。複数のKubernetesクラスターを一元管理し、エンタープライズレベルの運用、セキュリティ、ガバナンスを提供します。

詳細

Rancher(ランチャー)は、Rancher Labs(現SUSE)が開発したマルチクラスターKubernetes管理プラットフォームです。2014年にコンテナオーケストレーションプラットフォームとして開始し、Docker Swarm、Apache Mesosなどをサポートしていましたが、現在はKubernetesに特化。複数のKubernetesクラスター(オンプレミス、パブリッククラウド、エッジ)を単一のWebUIから統一管理できる点が最大の特徴です。クラスタープロビジョニング、アプリケーションカタログ、監視、ログ管理、バックアップ、セキュリティポリシー管理を統合し、マルチテナント環境での権限管理も強力。GitOpsワークフロー、Helm Chart管理、Prometheus/Grafana統合、災害復旧機能も内蔵。SUSE買収(2020年)後もオープンソースとしての地位を維持し、現在もCNCFランドスケープの中核プロジェクトとして位置づけられています。複雑なマルチクラスター環境の管理需要により成長を続け、金融、製造、政府機関等でのKubernetesガバナンス強化に貢献しています。

メリット・デメリット

メリット

  • マルチクラスター管理: 複数環境の統一オペレーション
  • 直感的WebUI: コマンドライン不要の視覚的管理
  • クラスタープロビジョニング: ワンクリックでのKubernetesクラスター作成
  • 統合監視: Prometheus、Grafana、Alertmanager内蔵
  • アプリケーションカタログ: Helm Chart管理とアプリストア
  • セキュリティ管理: RBAC、Pod Security Policy、ネットワークポリシー
  • 災害復旧: 自動バックアップとクラスター復旧機能
  • マルチテナント: プロジェクトベースの権限管理

デメリット

  • 複雑性: 大規模機能による学習コストの高さ
  • リソース消費: 管理プレーンのオーバーヘッド
  • ベンダー依存: SUSE エコシステムへの一定の依存
  • アップデート: Rancherとクラスターバージョン管理の複雑さ
  • カスタマイズ: 標準Kubernetesからの逸脱リスク
  • パフォーマンス: 多数クラスター管理時の応答性能
  • 移行コスト: 既存Kubernetes環境からの移行作業
  • トラブルシューティング: Rancher固有の問題解決が困難

主要リンク

書き方の例

Rancherサーバーのインストール

# Docker使用(単一ノード)
docker run -d --restart=unless-stopped \
  -p 80:80 -p 443:443 \
  --privileged \
  --name rancher-server \
  rancher/rancher:latest

# Helm使用(Kubernetesクラスター)
helm repo add rancher-stable https://releases.rancher.com/server-charts/stable
kubectl create namespace cattle-system

# SSL証明書設定(Let's Encrypt)
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.11.0/cert-manager.yaml

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

クラスター作成(Custom)

# Rancherエージェント実行用コマンド(各ノードで実行)
sudo docker run -d --privileged --restart=unless-stopped \
  --net=host -v /etc/kubernetes:/etc/kubernetes \
  -v /var/run:/var/run rancher/rancher-agent:v2.7.0 \
  --server https://rancher.example.com \
  --token <cluster-token> \
  --ca-checksum <ca-checksum> \
  --etcd --controlplane --worker

Project とNamespace管理

# project.yaml
apiVersion: management.cattle.io/v3
kind: Project
metadata:
  name: development-project
  namespace: cluster-id
spec:
  clusterId: cluster-id
  displayName: "Development Environment"
  description: "Development team workspace"
  
---
# namespace.yaml
apiVersion: v1
kind: Namespace
metadata:
  name: dev-apps
  annotations:
    field.cattle.io/projectId: "cluster-id:development-project"
  labels:
    field.cattle.io/projectId: "development-project"

App カタログからのデプロイ

# mysql-app.yaml
apiVersion: catalog.cattle.io/v1
kind: App
metadata:
  name: mysql-database
  namespace: dev-apps
spec:
  projectName: development-project
  targetNamespace: dev-apps
  externalId: catalog://?catalog=library&template=mysql&version=1.6.9
  values:
    mysqlRootPassword: "root-password"
    mysqlUser: "app-user"
    mysqlPassword: "app-password"
    mysqlDatabase: "application-db"
    persistence:
      enabled: true
      size: "10Gi"
      storageClass: "default"

Global DNS設定

# global-dns.yaml
apiVersion: management.cattle.io/v3
kind: GlobalDns
metadata:
  name: example-dns
spec:
  fqdn: "app.example.com"
  providerId: "cloudflare-provider"
  projectIds:
    - "cluster-id:development-project"
    - "cluster-id:production-project"
  multiClusterAppId: "multi-cluster-app"

Monitoring 設定

# monitoring-config.yaml
apiVersion: management.cattle.io/v3
kind: MonitorMetric
metadata:
  name: cpu-usage-alert
  namespace: cattle-monitoring-system
spec:
  clusterId: cluster-id
  expression: |
    (1 - avg(rate(node_cpu_seconds_total{mode="idle"}[5m]))) * 100
  description: "CPU usage percentage"
  threshold: 80
  comparison: "greater-than"
  duration: "5m"
  severity: "warning"

Pipeline設定(GitOps)

# pipeline.yaml
apiVersion: project.cattle.io/v3
kind: Pipeline
metadata:
  name: web-app-pipeline
  namespace: dev-apps
spec:
  projectId: "cluster-id:development-project"
  sourceCodeConfig:
    sourceCodeCredentialName: "github-credential"
    sourceCodeCredentialNamespace: "dev-apps"
  stages:
    - name: "Build"
      steps:
        - sourceCodeConfig:
            branchCondition: "only"
            branch: "main"
          runScriptConfig:
            image: "node:16"
            shellScript: |
              npm ci
              npm run build
              docker build -t myapp:${CICD_BUILD_NUMBER} .
    - name: "Deploy"
      steps:
        - applyYamlConfig:
            path: "./k8s/deployment.yaml"
            sourceCodeConfig:
              branchCondition: "only" 
              branch: "main"

RBAC設定

# rbac.yaml
apiVersion: management.cattle.io/v3
kind: GlobalRole
metadata:
  name: developer-role
rules:
- apiGroups: [""]
  resources: ["pods", "services"]
  verbs: ["get", "list", "create", "update", "patch", "delete"]
- apiGroups: ["apps"]
  resources: ["deployments", "replicasets"]
  verbs: ["get", "list", "create", "update", "patch", "delete"]

---
apiVersion: management.cattle.io/v3
kind: GlobalRoleBinding
metadata:
  name: developer-binding
subjects:
- kind: User
  name: "[email protected]"
globalRoleName: "developer-role"

Backup設定

# backup-config.yaml
apiVersion: resources.cattle.io/v1
kind: Backup
metadata:
  name: daily-backup
  namespace: cattle-resources-system
spec:
  resourceSetName: "rancher-resource-set"
  schedule: "0 2 * * *"  # 毎日午前2時
  retentionCount: 7
  storageLocation:
    s3:
      credentialSecretName: "s3-credentials"
      credentialSecretNamespace: "cattle-resources-system"
      bucketName: "rancher-backups"
      region: "us-west-2"
      folder: "cluster-backups"

CLI操作

# Rancher CLI インストール
curl -sL "https://github.com/rancher/cli/releases/download/v2.7.0/rancher-linux-amd64-v2.7.0.tar.gz" | tar xz
sudo mv rancher-v2.7.0/rancher /usr/local/bin/

# ログイン
rancher login https://rancher.example.com --token <api-token>

# クラスター操作
rancher clusters ls
rancher context switch <cluster-name>
rancher kubectl get nodes

# プロジェクト操作
rancher projects ls
rancher projects create development-env

# アプリ管理
rancher apps ls
rancher apps install cattle-global-data:library-mysql mysql-app \
  --answers mysqlRootPassword=password \
  --namespace dev-apps

# モニタリング
rancher kubectl top nodes
rancher kubectl top pods --all-namespaces