目的

使用kubectl连接到k8s群集

说明

在本实验中,您将kubectl根据admin用户凭据为命令行实用程序生成kubeconfig文件。

步骤

生成kubectl的使用admin用户认证的kubeconfig文件:

  1. kubectl config set-cluster kubernetes \
  2. --certificate-authority=ca.pem \
  3. --embed-certs=true \
  4. --server=https://master.k8s.com
  5. kubectl config set-credentials admin \
  6. --client-certificate=admin.pem \
  7. --client-key=admin-key.pem
  8. kubectl config set-context kubernetes \
  9. --cluster=kubernetes \
  10. --user=admin
  11. kubectl config use-context kubernetes

验证

shell># kubectl cluster-info 输出如下

  1. Kubernetes master is running at https://master.k8s.com
  2. To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

检查群集健康 shell># kubectl get componentstatuses 输出

  1. NAME STATUS MESSAGE ERROR
  2. controller-manager Healthy ok
  3. scheduler Healthy ok
  4. etcd-0 Healthy {"health": "true"}
  5. etcd-2 Healthy {"health": "true"}
  6. etcd-1 Healthy {"health": "true"}