Installing the Kubernetes CLI (kubectl)
To access your cluster by using the command line interface (CLI), you must install and configure kubectl, the Kubernetes command line tool.
-
Synchronize the clocks in between the client computer and the nodes in the cluster. To synchronize your clocks, you can use network time protocol (NTP). For more information about setting up NTP, see the user documentation for your operating system.
-
From the console, select the user icon
, then click Configure client.
-
Click Install CLI tools.Tip: You can also install kubectl without the console by entering the curl commands in this procedure at the command prompt, or in a Terminal window.
Note: To download the installation file by using curl commands, see Downloading the installation file by using curl commands. After you download the file, you can continue from step 3 to install kubectl.
-
Expand Install Kubernetes CLI to download the installer by using a
curlcommand. Copy and run the curl command for your operating system, then continue the installation procedure in the product documentation:Choose the curl command for the applicable operating system. For example, you can run the following command for macOS:
curl -kLo <install_file> https://<Cluster Master Host>:<Cluster Master API Port>/api/cli/kubectl-darwin-amd64Run the following example command to download the required files on the Linux operating system, replacing the variables with information for your environment:
curl -kLo <install_file> https://<Cluster Master Host>:<Cluster Master API Port>/api/cli/kubectl-linux-amd64 -
Change the file to an executable, then move the file to a directory that is included in your PATH environment variable. See the following commands where
<path_to_installer>is the location of the file that you downloaded and<install_file>is the name of the file:-
For Linux® and macOS, run the following commands to change the permissions of the file and move the file to a directory that is included in your PATH environment variable:
chmod 755 <path_to_installer>/<install_file>sudo mv <path_to_installer>/<install_file> /usr/local/bin/kubectlIn this example, it is moved to the
/usr/local/bin/kubectldirectory. -
For Windows, rename the downloaded file to
kubectland place the file in a directory that is listed in the PATH environment variable.Note: You can also download from Kubernetes. See Install and Set Up kubectl
.
-
-
Obtain the cluster configuration details. You can obtain the cluster configuration details by using cloudctl or console.
-
To obtain the configuration details from the console:
-
Log in to your cluster console.
-
Select the user icon
, then click Configure client. The cluster configuration details display and resemble the following code:
kubectl config set-cluster {cluster_name} --server=https://<Cluster Master Host>:8001 --insecure-skip-tls-verify=true kubectl config set-context {cluster_name}-context --cluster={cluster_name} kubectl config set-credentials {username} --token={token} kubectl config set-context {cluster_name}-context --user={username} --namespace=default kubectl config use-context {cluster_name}-contextNote: This configuration expires in 12 hours. To continue to use the CLI, you must log in and reconfigure
kubectlevery 12 hours. To avoid this limitation, you can configure your CLI by using service accounts. For more information, see Using service account tokens to connect with the API server. -
Copy and paste the configuration information to your command line, and press Enter.
-
-
To obtain the configuration details from cloudctl:
- Install cloudctl and log in to your cluster. See Installing cloudctl.
-
Downloading the installation file by using curl commands
You can complete the following steps to download the installation file:
-
Get the service hostnames. Use the
management-ingressservice hostname in the command to download the installation file.oc get route -n kube-systemFollowing is a sample output:
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD icp-console cp-console.apps.an.os.example.abc.com management-ingress <all> passthrough/Redirect None icp-proxy cp-proxy.apps.an.os.example.abc.com nginx-ingress https passthrough/Redirect None -
Download the installation file.
-
For macOS, run the following command:
curl -kLo kubectl-darwin-amd64-v1.13.11 https://cp-console.apps.an.os.example.abc.com:443/api/cli/kubectl-linux-amd64 -
For Linux® x86_64, run the following command:
curl -kLo kubectl-linux-amd64-v1.13.11 https://cp-console.apps.an.os.example.abc.com:443/api/cli/kubectl-linux-amd64 -
For Linux on Power (ppc64le), run the following command:
curl -kLo kubectl-linux-ppc64le-v1.13.11 https://cp-console.apps.an.os.example.abc.com:443/api/cli/kubectl-linux-ppc64le -
For Windows (64-bit), run the following command:
curl -kLo kubectl-win-amd64-v1.13.11.exe https://cp-console.apps.an.os.example.abc.com:443/api/cli/kubectl-win-amd64.exe -
For Linux on IBM Z and LinuxONE, run the following command:
curl -kLo kubectl-linux-s390x-v1.13.11 https://cp-console.apps.an.os.example.abc.com:443/api/cli/kubectl-linux-s390x
-