Kubenetes is a Open Source container cluster management tool. IBM® Bluemix® Container Service offers several options to configure and customize Kubernetes cluster to meet the functional and non-functional requirements of your organization. IBM has replaced its previous architecture of container groups with that of kubernetes to achieve high availability. Apart from introducing kubernetes there has been changes in bluemix commandline as well. IBM has moved from IBM Container (ic) command line to Container Registry (cr) commandline to upload custom docker images to bluemix private registry. IBM has also introduced Container Service (cs) command which would help in creating and managing kubernetes cluster from commandline. The login command has been appended with SSO switch for two factor authentication.
This article is an extension to my previous article on IBM containers which show cased Implementation Wildfly as container image on IBM Bluemix. The same is further extended with Kubernetes. This article specifically deals with Bluemix Lite deployment of Kubernetes.
Bluemix Commandline Installation and Configuration
It is assumed that one has already installed Bluemix (bx) commandline in his operating system. This can be done using binary installer available on Bluemix page. Once that is done one needs to add plugins to this commandline environment. Login into Bluemix region
OOnce we have logged in into the Organization one can go ahead and install respective plugins
Once the Container Service (cs) plugin is installed one can test this using init command.
Installing Container Registry plugin.
Container Registry (cr) plugin can be tested using login command. This is essential pre-requisite to upload docker images to IBM Bluemix private registry.
Add a namespace in Bluemix private registry if previously not done
Download and Install kubectl commandline in your operating system path. On windows one can copy this command line in System32 folder of Windows directory.
Note: After you have created the cluster it is mandatory to run the below command to for kubectl command to work properly.
bx cs cluster-config <<CLUSTER_NAME>>
Kubernetes Basic Concepts
I will not discuss all the concepts here and will adhare to only those which are required by developer to create a YAML file.
Pods: are the smallest deployable unit of also referred to as docker containers.
Services: are an abstaction for a logical sets of pods.
Labels: are key/value pairs attached to objects used for identification.
Replica Sets: ensures specific number of pods are running.
Applications within a pod also have access to shared volumes, which are defined as part of a pod and are made available to be mounted into each application’s filesystem. In terms of Docker constructs, a pod is modelled as a group of Docker containers with shared namespaces and shared volumes.
The Kubernetes master in IBM Bluemix for each cluster is managed by IBM, is highly available, and includes IBM® Bluemix® Container Service security settings that ensure security compliance and secure communication to and from the worker nodes. Updates are performed by IBM as required. The dedicated Kubernetes master centrally controls and monitors all Kubernetes resources in the cluster. Based on the deployment requirements and capacity in the cluster, the Kubernetes master automatically schedules your containerized apps to deploy across available worker nodes.
Bluemix Lite deployment make use of NodePort where in when you expose your app by creating a Kubernetes service of type NodePort, a NodePort in the range of 30000 – 32767 and an internal cluster IP address is assigned to the service. The NodePort service serves as the external entrypoint for incoming requests for your app. The assigned NodePort is publicly exposed in the kubeproxy settings of each worker node in the cluster. Every worker node starts listening on the assigned NodePort for incoming requests for the service. To access the service from the internet, you can use the public IP address of any worker node that was assigned during cluster creation and the NodePort in the format <ip_address>:<nodeport>.
When a public request arrives at the NodePort service, it is automatically forwarded to the internal cluster IP of the service and further forwarded from the kubeproxy component to the private IP address of the pod where the app is deployed. The cluster IP is accessible inside the cluster only. If you have multiple replicas of your app running in different pods, the kubeproxy component load balances incoming requests across all replicas
Settings Kubernetes in IBM Bluemix
Click on Kubernetes cluster option in Catalog of your Bluemix account
and wait for few minutes before you see Ready in green. Click on Access link on the left to see the instructions to access cluster from commandline.
Download/build docker image which you want to deploy on Kubernetes on Bluemix. In this example I will be showing deployment of Wildfly Server.
Check in your local docker registry weather the image has been downloaded successfully.
Upload this Image in local bluemix docker registry. For this one needs to tag this Image with bluemix registry URL.
Now upload the image to bluemix local registry
check weather the Image is uploaded successfully in your private registry in Bluemix
Writing a YAML file
Download any existing standard Pod and Service YAML and modify it as per your reuquirement. Give reference to your private registry URL of docker image that you have just uploaded in previous step.
Run kubectl command on the yml of both the files that you have just created.
Since we have already logged in into Bluemix and initiated container service (cs) using init command, the kubectl command will directly create pod in Bluemix kubernets. Check weather POD is created using below command.
Verify the details of private IP by the below command.
All pods that are deployed to a worker node are also assigned a private IP address. Pods are assigned an IP in the 172.30.0.0/16 private address range and are routed between worker nodes only. To avoid conflicts, do not use this IP range on any nodes that will communicate with your worker nodes. Worker nodes and pods can securely communicate on the private network by using the private IP addresses. However, when a pod crashes or a worker node needs to be re-created, a new private IP address is assigned.
Enable console and check the logs.
Open the URL in browser and check logs to verify integrity of Installation
On clicking the Elipsis button on the extreme right, the logs will be opened in a new tab in your browser
Get the details of Public IP and Ports
The URL will be formed by combining Public IP and Node Port which is mapped to 8080 as http://126.96.36.199:31141 .
Addendum - Binding existing Bluemix Services with Kubernetes Cluster
To bind an existing Bluemix services to Kubernetes cluster one can use the below steps:
1. Get the namespace of your Kubernetes cluster
2. Bind the existing service with Kuberetes using the default namespace
3. Kubernets and IBM Bluemix: https://www.ibm.com/blogs/bluemix/2017/05/kubernetes-and-bluemix-container-based-workloads-part1/