Chuyển đến nội dung chính
Kết nối cụm Kubernetes của bạn để Kai có thể phân tích workload, tối ưu tài nguyên và quản lý vận hành cluster. Kubernetes kết nối qua tự động khám phá từ cloud provider (dành cho EKS, GKE và AKS) hoặc service-account token kèm thông tin endpoint cluster cho các cụm tự quản lý.

Điều kiện tiên quyết

Cài đặt Metrics Server trước khi kết nối — thành phần này bắt buộc để lấy metrics tài nguyên pod và node:
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
Thành phầnMục đích
Metrics ServerBắt buộc để lấy metrics tài nguyên pod và node
kube-state-metricsMetrics cluster nâng cao (tùy chọn)
Kết nối mạngCloudThinker phải tiếp cận được API server của cluster

Nền tảng được hỗ trợ

Nền tảngHỗ trợ
Amazon EKSTất cả phiên bản
Google GKEStandard, Autopilot
Azure AKSTất cả phiên bản
Tự quản lýKubernetes 1.24+
RancherRKE, RKE2
OpenShift4.x

Thiết lập

Tự động khám phá từ kết nối cloud

Nếu bạn đã kết nối AWS, GCP hoặc Azure, các cụm Kubernetes được quản lý sẽ được tự động khám phá.
1

Kết nối cloud provider

Thiết lập kết nối AWS, GCP hoặc Azure trước.
2

Cluster được tự động khám phá

Các cụm EKS, GKE hoặc AKS xuất hiện tự động trong CloudThinker. Chọn cluster nào cần bật để phân tích. CloudThinker hiển thị trạng thái Connected cho mỗi cluster đã kích hoạt.

Chi tiết kết nối

Định dạng kubeconfig mà CloudThinker sử dụng cho kết nối trực tiếp:
apiVersion: v1
kind: Config
clusters:
- cluster:
    certificate-authority-data: <base64-encoded-ca-cert>
    server: https://your-cluster-endpoint:6443
  name: your-cluster
contexts:
- context:
    cluster: your-cluster
    user: cloudthinker-readonly
  name: cloudthinker-context
current-context: cloudthinker-context
users:
- name: cloudthinker-readonly
  user:
    token: <your-service-account-token>

Quyền bắt buộc

Tối thiểu (chỉ đọc)

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: cloudthinker-readonly
rules:
- apiGroups: [""]
  resources: ["pods", "nodes", "services", "namespaces", "events", "configmaps"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
  resources: ["deployments", "replicasets", "statefulsets", "daemonsets"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["autoscaling"]
  resources: ["horizontalpodautoscalers"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["metrics.k8s.io"]
  resources: ["pods", "nodes"]
  verbs: ["get", "list"]

Khuyến nghị (phân tích toàn diện)

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: cloudthinker-full-analysis
rules:
- apiGroups: [""]
  resources: ["pods", "nodes", "services", "namespaces", "events", "configmaps", "secrets", "persistentvolumeclaims", "resourcequotas", "limitranges", "replicationcontrollers"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
  resources: ["deployments", "replicasets", "statefulsets", "daemonsets"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["batch"]
  resources: ["jobs", "cronjobs"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["networking.k8s.io"]
  resources: ["ingresses", "networkpolicies"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["autoscaling"]
  resources: ["horizontalpodautoscalers"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["metrics.k8s.io"]
  resources: ["pods", "nodes"]
  verbs: ["get", "list"]
Bắt đầu với ClusterRole tối thiểu và mở rộng sang role phân tích toàn diện chỉ khi bạn cần tập khả năng rộng hơn. Không bao giờ cấp verbs ghi — get, list và watch là đủ cho mọi khả năng của Kai.

Khả năng của agent

Sau khi kết nối, Kai có thể kiểm tra và tối ưu cluster của bạn.
Khả năngMô tả
Phân tích tài nguyênMức sử dụng CPU/memory của pod, requests so với limits
Sức khỏe nodeTrạng thái node, dung lượng, tài nguyên có thể phân bổ
Tối ưu workloadKhuyến nghị right-sizing, điều chỉnh HPA
Khắc phục sự cốCrashLoopBackOff, OOMKilled, pod đang chờ
Kiểm tra bảo mậtXem xét RBAC, bảo mật pod, network policy

Xác minh kết nối

@kai check the cluster connection and list all namespaces and node count

Ví dụ prompt

@kai analyze pod resource utilization in the production namespace and #report the top CPU and memory consumers
@kai investigate crash loops in the payment service and #recommend a fix
@kai check node resource pressure across the cluster and #alert if any node is near capacity

Khắc phục sự cố

Xác minh endpoint API server có thể truy cập từ internet. Kiểm tra rằng firewall và security group cho phép IP của CloudThinker. Với cluster riêng tư, hãy thiết lập VPN hoặc bastion và xác nhận chứng chỉ API server hợp lệ.
Xác minh service account token chính xác. Kiểm tra ClusterRoleBinding đã được áp dụng và token chưa hết hạn. Xác nhận service account tồn tại trong namespace đúng.
Xác minh Metrics Server đã cài đặt bằng cách chạy kubectl top nodes. Kiểm tra các pod Metrics Server đang chạy và API metrics.k8s.io khả dụng.
Xác minh ClusterRole bao gồm quyền liệt kê namespace. Kiểm tra xem RBAC có hạn chế truy cập một số namespace nhất định không và xác nhận service account binding là cluster-wide.

Bảo mật

  • Quyền tối thiểu — chỉ cấp các quyền mà agent cần cho trường hợp sử dụng của bạn; bắt đầu với quyền chỉ đọc và mở rộng sau.
  • Chỉ đọc theo mặc định — sử dụng thông tin xác thực chỉ đọc trừ khi bạn muốn agent thực hiện thay đổi qua kết nối này.
  • Xoay vòng thông tin xác thực — xoay vòng khóa và token theo lịch trình thông thường của bạn; CloudThinker sẽ lấy giá trị mới khi bạn cập nhật kết nối.
  • Thu hồi khi bàn giao — xóa thông tin xác thực tại nhà cung cấp khi bạn xóa một kết nối hoặc khi đồng nghiệp rời nhóm.
  • Chỉ đọc — không bao giờ cấp verbs ghi cho service account CloudThinker; get, list và watch là đủ cho mọi khả năng của agent.
  • Cô lập namespace — giữ service account trong một namespace riêng (ví dụ: cloudthinker) để đơn giản hóa kiểm toán và thu hồi quyền.

Liên quan

Kai Agent

Agent tối ưu Kubernetes
https://mintcdn.com/cloudthinker/aLd-ttc-SCW-aFky/images/icons/aws.svg?fit=max&auto=format&n=aLd-ttc-SCW-aFky&q=85&s=45d526a3e9345214c0345f277da2e829

Kết nối AWS

Kết nối AWS để tự động khám phá EKS