目的
使用kubectl连接到k8s群集
说明
在本实验中,您将kubectl根据admin用户凭据为命令行实用程序生成kubeconfig文件。
步骤
生成kubectl的使用admin用户认证的kubeconfig文件:
kubectl config set-cluster kubernetes \
--certificate-authority=ca.pem \
--embed-certs=true \
--server=https://master.k8s.com
kubectl config set-credentials admin \
--client-certificate=admin.pem \
--client-key=admin-key.pem
kubectl config set-context kubernetes \
--cluster=kubernetes \
--user=admin
kubectl config use-context kubernetes
验证
shell># kubectl cluster-info 输出如下
Kubernetes master is running at https://master.k8s.com
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
检查群集健康 shell># kubectl get componentstatuses 输出
NAME STATUS MESSAGE ERROR
controller-manager Healthy ok
scheduler Healthy ok
etcd-0 Healthy {"health": "true"}
etcd-2 Healthy {"health": "true"}
etcd-1 Healthy {"health": "true"}