Kubernetes 简明教程

Kubernetes - Kubectl

Kubectl 是与 Kubernetes API 交互的命令行实用程序。它是一个用于在 Kubernetes 集群中通信和管理容器的界面。

Kubectl is the command line utility to interact with Kubernetes API. It is an interface which is used to communicate and manage pods in Kubernetes cluster.

需要在本地设置 kubectl 以与 Kubernetes 集群交互。

One needs to set up kubectl to local in order to interact with Kubernetes cluster.

Setting Kubectl

使用 curl 命令将可执行文件下载到本地工作站。

Download the executable to the local workstation using the curl command.

On Linux

$ curl -O https://storage.googleapis.com/kubernetesrelease/
release/v1.5.2/bin/linux/amd64/kubectl

On OS X workstation

$ curl -O https://storage.googleapis.com/kubernetesrelease/
release/v1.5.2/bin/darwin/amd64/kubectl

下载完成后,将二进制文件移动到系统的路径中。

After download is complete, move the binaries in the path of the system.

$ chmod +x kubectl
$ mv kubectl /usr/local/bin/kubectl

Configuring Kubectl

以下是执行配置操作的步骤。

Following are the steps to perform the configuration operation.

$ kubectl config set-cluster default-cluster --server = https://${MASTER_HOST} --
certificate-authority = ${CA_CERT}

$ kubectl config set-credentials default-admin --certificateauthority = ${
CA_CERT} --client-key = ${ADMIN_KEY} --clientcertificate = ${
ADMIN_CERT}

$ kubectl config set-context default-system --cluster = default-cluster --
user = default-admin
$ kubectl config use-context default-system
  1. Replace ${MASTER_HOST} with the master node address or name used in the previous steps.

  2. Replace ${CA_CERT} with the absolute path to the ca.pem created in the previous steps.

  3. Replace ${ADMIN_KEY} with the absolute path to the admin-key.pem created in the previous steps.

  4. Replace ${ADMIN_CERT} with the absolute path to the admin.pem created in the previous steps.

Verifying the Setup

要验证 kubectl 是否正常工作,请检查 Kubernetes 客户端是否设置正确。

To verify if the kubectl is working fine or not, check if the Kubernetes client is set up correctly.

$ kubectl get nodes

NAME       LABELS                                     STATUS
Vipin.com  Kubernetes.io/hostname = vipin.mishra.com    Ready