Kubernetes is the most commonly used container cluster manager. Installing Kubernetes is a complex task, requiring multiple commands and configuration settings. The IBM Bluemix cloud platform offers Kubernetes as a managed cloud service. A Kubernetes cluster may be spun from the Bluemix Console. In this tutorial, we shall discuss Kubernetes on IBM Bluemix. This tutorial assumes an introductory knowledge of Docker and Kubernetes because we shall be using Docker image/s to create Kubernetes objects: nodes, services, Pods, and replica sets. This tutorial has the following sections:
- Setting the Environment
- Creating a Kubernetes Cluster on Bluemix
- Accessing the Kubernetes Cluster
- Installing the Container Service Plug-in
- Logging in to the Bluemix Account
- Initializing the IBM Bluemix Container Service Plug-in
- Using kubectl to Access the Kubernetes Cluster
- Accessing the Kubernetes Dashboard
- Creating Kubernetes Services in the Dashboard
As a pre-requisite, an IBM Bluemix account is required. An account may be registered at https://console.ng.bluemix.net/registration/. We have used the Windows OS platform for accessing the Kubernetes cluster on IBM Bluemix for which two command line interfaces (CLIs) are required. The two CLIs are Bluemix CLI and Kubernetes CLI called kubectl. Download the Bluemix CLI Windows (64-bit) binaries Bluemix_CLI_0.5.2_amd64.exe from https://clis.ng.bluemix.net/ui/home.html, as shown in Figure 1. To install, click the Bluemix_CLI_0.5.2_amd64.exe application.
Figure 1: Downloading Bluemix CLI
The command line interface for Kubernetes kubectl application, kubectl.exe, may be downloaded from https://github.com/eirslett/kubectl-windows/releases. Double-click the kubectl.exe application to install kubectl on Windows. Restart the system for Bluemix CLI configurations to take effect.
To create a Kubernetes cluster, log in to the Bluemix account and click Catalog, as shown in Figure 2.
Figure 2: Selecting Catalog in Bluemix
Using the Filter, search for "kubernetes" and select the service Kubernetes Cluster, as shown in Figure 3.
Figure 3: Selecting Kubernetes Cluster
In the Create a Kubernetes Cluster dialog, specify a cluster name in the Cluster Name field and select the cluster location in the Location field, and click on Create Cluster, as shown in Figure 4.
Figure 4: Create a Kubernetes Cluster
A Welcome to the Container Service Beta dialog gets displayed. Click I'm ready, as shown in Figure 5.
Figure 5: Welcome to the Container Service Beta
The Kubernetes cluster begins to get deployed, as indicated by the "Deploying" message for kube-cluster in Figure 6.
Figure 6: Kubernetes Cluster getting deployed
When the Kubernetes cluster gets deployed, the message becomes "Ready," as shown in Figure 7.
Figure 7: Kubernetes Cluster Ready
The Overview, shown in Figure 8, lists the Summary of the cluster, including the Cluster ID, Kubernetes version, Location, and Managed from region. The number of Worker nodes, including node status, is also shown with 1 being Ready.
Figure 8: Cluster overview
The Worker Nodes table lists one node in Ready state. The Private IP, Public IP, and Kube version of the cluster is also listed, as shown in Figure 9.
Figure 9: Worker Nodes
The Kubernetes cluster is an application itself and gets listed in the All Apps table as kube-cluster cluster, as shown in Figure 10.
Figure 10: All Apps lists the kube-cluster
The Kubernetes cluster may be accessed on the command line or from a dashboard. We shall discuss each of these next. To access the cluster from the command line, some pre-requisite tasks need to be performed, which we shall discuss first.
In a command shell, install the IBM Bluemix Container Service plug-in with the following Bluemix CLI command:
bx plugin install container-service -r Bluemix
Regardless of from which directory the preceding command is run, the plug-in gets installed in a user directory C:\Users\<user>\.bluemix\plugins\container-service; the <user> represents the variable user. The output from the preceding command is as follows:
C:\Kubernetes>bx plugin install container-service -r Bluemix Looking up 'container-service' from repository 'Bluemix'... Attempting to download the binary file... 21202432 bytes downloaded Installing binary... OK Plug-in 'container-service 0.1.238' was successfully installed into C:\Users\Deepak Vohra\.bluemix\plugins \container-service.
Next, log in to the Bluemix account from the command-line, using the Bluemix CLI.
bx login -a https://api.ng.bluemix.net
As the output indicates, a user is prompted for e-mail information. Specify the Email and subsequently the Password prompt is displayed. Provide the password and the user gets authenticated. Select an account to log in to and the user gets logged into the account.
C:\Kubernetes>bx login -a https://api.ng.bluemix.net API endpoint: https://api.ng.bluemix.net Email> email@example.com Password> Authenticating... OK Select an account (or press enter to skip): 1. NuBean (c1b88fbec5a71a6231a9518666d2714f) Enter a number> 1 Targeted account NuBean (c1b88fbec5a71a6231a9518666d2714f) Targeted org dvohra15 Targeted space dev https://api.ng.bluemix.net (API version: 2.54.0) Region: us-south User: firstname.lastname@example.org Account: NuBean (c1b88fbec5a71a6231a9518666d2714f) Org: dvohra15 Space: dev
To initialize the IBM Bluemix Container Service plug-in, run the following Bluemix CLI command.
bx cs init
The Container Service plug-in gets initialized.
C:\Kubernetes>bx cs init Using default API endpoint: https://us-south.containers.bluemix.net OK Set the terminal context to the cluster. C:\Kubernetes>bx cs cluster-config kube-cluster Downloading cluster config for kube-cluster OK The configuration for kube-cluster was downloaded successfully. Export environment variables to start using Kubernetes. SET KUBECONFIG=C:\Users\Deepak Vohra\.bluemix\plugins \container-service\clusters\kube-cluster \kube-config-prod-dal10-kube-cluster.yml
The output from the preceding command outputs a command to use to set the KUBECONFIG environment variable to the configuration file. Copy and paste the command in the cmd shell or use a slight variation of the command (such as adding double-quotes on the file path) to set the KUBECONFIG environment variable.
C:\Kubernetes>SET KUBECONFIG="C:\Users\Deepak Vohra \.bluemix\plugins\container-service\clusters\kube-cluster \kube-config-prod-dal10-kube-cluster.yml"
In a cmd shell, run the following kubectl command to list the cluster nodes.
kubectl get nodes
Initially, the cluster node may not get listed or could be in the NotReady state, as indicated by the following output.
C:\Kubernetes>kubectl get nodes NAME LABELS STATUS AGE 126.96.36.199 arch=amd64,beta.kubernetes.io /arch=amd64,beta.kubernetes.io/os= linux,kubernetes.io/hostname=188.8.131.52 NotReady 7m
Run the preceding command again. After a while, the cluster node should be listed as Ready.
C:\Kubernetes>kubectl get nodes NAME LABELS STATUS AGE 184.108.40.206 arch=amd64,beta.kubernetes.io /arch=amd64,beta.kubernetes.io/os= linux, kubernetes.io/hostname=220.127.116.11, privateVLAN=1518887,publicVLAN=15188 89 Ready 20m
To access the Kubernetes dashboard, first run the following command to start a proxy to the Kubernetes API server:
As the command output in Figure 11 indicates, a proxy to the API server gets started.
Figure 11: Starting proxy to API server on port 8001
Open URL http://127.0.0.1:8001/ui in a browser to view the Kubernetes dashboard, as shown in Figure 12.
Figure 12: The Kubernetes dashboard
To create a Kubernetes service, click Create, as shown in Figure 13.
Figure 13: Click CREATE to create a service
In the Deploy a Containerized App dialog, specify an App name (oracle-database-11xe), the Container image (sath89/oracle-xe-11g), Number of pods to run (1), Service External/Internal/None, Port(1521), Target Port(1521), and service Protocol (TCP), as shown in Figure 14.
Figure 14: Specifying Containerized App details
Optionally, Labels may be specified. The Namespace may also be set, the default namespace being "default." CPU requirement (cores), Memory requirement (MB), Run command including run command args, whether to run as privileges, and Environment variables also may be specified. Click DEPLOY to deploy the service, as shown in Figure 15.
Figure 15: Deploying a service
The service oracle-database-11xe gets deployed and is listed in Services in addition to the Kubernetes service, as shown in Figure 16.
Figure 16: Service oracle-database-11xe
Click the service link and the service details, including Pods, in the service get displayed, as shown in Figure 17.
Figure 17: Service details
To display the replica sets (see Figure 18) in the service, click the Replica Sets in the margin.
Figure 18: Replica Sets
Similarly, deploy another service for nginx server using the nginx Docker image, as shown in Figure 19.
Figure 19: Deploying the nginx service
The Deployments list both the Oracle database deployment and the Nginx server deployment, as shown in Figure 20. The CPU Usage and Memory Usage are also shown.
Figure 20: Deployments
Scroll down for the Replica Sets and Pods in the deployments, as shown in Figure 21.
Figure 21: Replica Sets and Pods in Deployments
The Services should list three services—Kubernetes, oracle-database-11xe, and nginx—as shown in Figure 22.
Figure 22: Services
In the Kubernetes Dashboard, click Nodes to display the Nodes in the cluster, as shown in Figure 23.
Figure 23: Nodes in the cluster
In the cmd shell, list the services with the kubectl get services command.
C:\Kubernetes>kubectl get services NAME CLUSTER_IP EXTERNAL_IP PORT(S) SELECTOR AGE kubernetes 10.10.10.1 <none> 443/TCP <none> 57m nginx 10.10.10.7 80/TCP app=nginx 2m oracle- 10.10.10.92 1521/TCP app=oracle- 6m database-11xe database-11xe
To list the Pods, run the kubectl get pods command.
C:\Kubernetes>kubectl get pods NAME READY STATUS RESTARTS AGE nginx-4153138332-2x8p1 1/1 Running 0 2m oracle-database-11xe-1994322078-114wr 1/1 Running 0 5m
Installing Kubernetes cluster is a complex task. The IBM Bluemix managed service Kubernetes Cluster service simplifies the tasks of creating a Kubernetes cluster, and subsequently accessing and using the Kubernetes cluster.