This article is the second in my series about IBM Cloud Kubernetes. This article requires that you have set up your IBM Cloud Kubernetes cluster. See my article IBM Cloud – Getting Started with a Free Kubernetes Cluster
In this article, we will download and install the IBM Cloud and Kubernetes CLI tools. We will then authenticate with IBM Cloud, with Kubernetes and run some basic commands. In the next article, we will deploy a Hello World application on Kubernetes.
Note: This article will recommend installing the tools differently than the documentation. The reason is if you follow the documentation the setup will fail.
Step 1 – Install the IBM Cloud CLI
The IBM Cloud CLI is a command-line tool for interfacing with IBM Cloud. This tool is also used for creating, developing, and deploying cloud applications.
For Windows, there are 32-bit and 64-bit versions. This article is written for Windows 10 Professional 64-bit.
Go to this page and download the Windows 64-bit Installer.
Once the download completes, launch the installer and complete the installation. Reboot your system once the installation completes.
The IBM Cloud command-line tools are installed to:
1 |
C:\Program Files\IBM\Cloud\bin |
Install the Developer Tools CLI plug-in
1 |
ibmcloud plugin install dev |
Install the Object Storage CLI plug-in
1 |
ibmcloud plugin install cloud-object-storage |
Install the Container Registry CLI plug-in
1 |
ibmcloud plugin install container-registry |
Install the Kubernetes Service CLI plug-in
1 |
ibmcloud plugin install container-service |
There are many more plug-ins that you can install.
Verify the installed CLI plug-ins
1 |
ibmcloud plugin list |
Example output:
1 2 3 4 5 6 7 |
Listing installed plug-ins... Plugin Name Version Status container-registry 0.1.433 container-service/kubernetes-service 0.4.38 dev 2.4.0 cloud-object-storage 1.1.0 |
Step 2 – Install the Kubernetes CLI
Installing the IBM Cloud Kubernetes CLI is a bit of a mess. You need to know the version of your Kubernetes cluster and then download the matching kubectl version. At the time I wrote this article, this version 1.14.
Click on the following link and download kubectl.exe to a temporary directory:
Download kubectl version 1.14.8
- Open an elevated Command Prompt (Run as Administrator).
- Copy kubectl.exe to the IBM Cloud CLI installation directory. On my system this directory is
C:\Program Files\IBM\Cloud\bin
.
Verify the installed CLI programs
At a normal Windows Command Prompt:
1 |
kubectl version --short |
Example output:
1 2 |
Client Version: v1.14.8 Server Version: v1.14.8+IKS |
Step 3 – Log in to IBM Cloud
This step authenticates the CLI with IBM Cloud. You will need your email address and password for your account.
At a normal Windows Command Prompt:
1 |
ibmcloud login |
List your IBM Cloud Kubernetes Clusters:
1 |
ibmcloud ks cluster ls |
Example output:
1 2 |
Name ID State Created Workers Location Version Resource Group Name Provider mycluster bmoigf8d0p2ff4mhcdlg normal 18 hours ago 1 Dallas 1.14.8_1536 Default classic |
Note the Name and Resource Group Name in the output. For my setup, the Resource Group Name is Default. Use the listed name for the next command.
Set the default Resource Group Name
1 |
ibmcloud target -g Default |
Example output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Targeted resource group Default API endpoint: https://cloud.ibm.com Region: us-south User: user@example.com Account: Hanley (1234567890abcdef1234567890abcdef) <-> 1234599 Resource group: Default CF API endpoint: Org: Space: Tip: If you are managing Cloud Foundry applications and services - Use 'ibmcloud target --cf' to target Cloud Foundry org/space interactively, or use 'ibmcloud target --cf-api ENDPOINT -o ORG -s SPACE' to target the org/space. - Use 'ibmcloud cf' if you want to run the Cloud Foundry CLI with current IBM Cloud CLI context. |
Step 4 – Set up the Kubernetes Cluster Context
Next, we will set up the CLI to communicate with your cluster. These commands must be run for each session of the CLI.
Set the Kubernetes Cluster Context
This command sets the cluster context, displays a command to set an environment variable and downloads the Kubernetes configuration files.
1 |
ibmcloud ks cluster config --cluster mycluster |
Example output:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
WARNING: The behavior of this command in your current CLI version is deprecated, and becomes unsupported when CLI version 1.0 is released in March 2020. To use the new behavior now, set the 'IKS_BETA_VERSION' environment variable. In Command Prompt, run 'SET IKS_BETA_VERSION=1'. Note: Changing the beta version can include other breaking changes. For more information, see http://ibm.biz/iks-cli-v1 OK The configuration for mycluster was downloaded successfully. Export environment variables to start using Kubernetes. PowerShell $env:KUBECONFIG = "C:\Users\username\.boilermakers\plugins\container-service\clusters\mycluster\kube-config-hou02-mycluster.yml" Command Prompt SET KUBECONFIG=C:\Users\username\.bluemix\plugins\container-service\clusters\mycluster\kube-config-hou02-mycluster.yml |
Copy the command above that starts with SET KUBECONFIG. Run this command in the same command prompt. This command sets the environment variable KUBECONFIG to the path of the Kubernetes configuration file.
Display information about the Kubernetes cluster
1 |
kubectl cluster-info |
Example output:
1 2 3 4 |
Kubernetes master is running at https://c5.dal12.containers.cloud.ibm.com:26991 CoreDNS is running at https://c5.dal12.containers.cloud.ibm.com:26991/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy kubernetes-dashboard is running at https://c5.dal12.containers.cloud.ibm.com:26991/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy Metrics-server is running at https://c5.dal12.containers.cloud.ibm.com:26991/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy |
Display information about the Worker Nodes
1 |
kubectl get nodes |
Example output:
1 2 |
NAME STATUS ROLES AGE VERSION 10.47.87.67 Ready <none> 19h v1.14.7+IKS |
Display detailed information about the Kubernetes Cluster configuration
1 |
kubectl config view |
Example output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
apiVersion: v1 clusters: - cluster: certificate-authority: ca-hou02-mycluster.pem server: https://c5.dal12.containers.cloud.ibm.com:26991 name: mycluster contexts: - context: cluster: mycluster namespace: default user: user@example.com name: mycluster current-context: mycluster kind: Config preferences: {} users: - name: user@example.com user: auth-provider: config: client-id: kube client-secret: kube id-token: <REMOVED> idp-issuer-url: https://iam.bluemix.net/identity refresh-token: <REMOVED> name: oidc |
Summary
The IBM Cloud and Kubernetes command-line tools are now set up. Spend some time learning about the various commands and options. In the next article, we will deploy a Hello World application on Kubernetes.
More Information
- Setting up the IBM Cloud CLI
- IBM Cloud Kubernetes Service CLI
- Overview of kubectl
- kubectl Cheat Sheet
Credits
I write free articles about technology. Recently, I learned about Pexels.com which provides free images. The image in this article is courtesy of Michel Berube at Pexels.
I design software for enterprise-class systems and data centers. My background is 30+ years in storage (SCSI, FC, iSCSI, disk arrays, imaging) virtualization. 20+ years in identity, security, and forensics.
For the past 14+ years, I have been working in the cloud (AWS, Azure, Google, Alibaba, IBM, Oracle) designing hybrid and multi-cloud software solutions. I am an MVP/GDE with several.
Leave a Reply