Overview

Skill Level: Beginner

This recipe provides step-by-step instruction to deploy an application in docker container to Kubernetes Cluster in Bluemix using Kubernetes CLI. The sample application used is the same one presented in Kavisuresh’s recipe published in December, 2016.

Ingredients

  • IBM Bluemix Account (https://console.ng.bluemix.net)
  • Local workstation

Step-by-step

  1. Login to your IBM Bluemix Account

    1. From your web borwser, login to your IBM Bluemix account at https://console.ng.bluemix.net.

    Note: if you do not have an IBM Bluemix account, you can open a 30-day trial account with a valid email address.

  2. Create a Kubernetes Cluster in Bluemix

    1. After login to your Bluemix account, click on the Catalog link on the top, select Apps -> Containers from the left navigation menu and click on the Kubernetes Cluster as shown below:

    p1

    2. In the Create a Kubernates Cluster page, enter your Cluster Name, set the Cluster type as Free and select the Bluemix Data Center Location from the dropdown list (dal10 is the default), then click on Submit.

    p2

    Your will see your Kubernetes Cluster is now in Deploying status.

    p3

    When the deployment is done, you can see your Kubernetes cluster status is updated as Deployed.

    p4


  3. Install Bluemix CLI and Kubernetes CLI

    1. After your Bluemix Kubernates cluster is deployed, you need to configure your local workstation to run Bluemix CLI and Kubernetes CLI. To do this, click on the Access cluster link on the Kubernates cluster Summary page.

    p5

    a. Install Bluemix CLI

    i. Click on the Download Bluemix CLI link.

    p6

    ii. Select and download the CLI for your OS to your local workstation, and follow the direction on the page to run the setup script in the package to install the Bluemix CLI on your local workstation.

    p7

    iii. After the Bluemix CLI is installed, install the Container Service CLI plugin with the command: 

    bx plugin install container-service -r Bluemix

    b. Install Kubernetes CLI

    i. Click on the Kubernetes CLI (kubectl) link.

    p8

    ii. In the Kubernetes Guide page click on the Installing and Setting Up kubectl link.p9

    iii. Follow the directions in the download page to download and install Kubernetes CLI.p10

  4. Run Kubernetes CLI

    1. In your local workstation terminal window, login to Bluemix from your local workstation with command:

    bx login -a https://api.ng.bluemix.net

    2. Login to the Bluemix Container Service plugin in the Bluemix CLI with command:

    bx cs init

    3. Set the Kiubernetes cluster you created in Bluemix as the context for this session. Complete this configuration step every time you want to work with your cluster with the CLI.

    a. Download the Kubernetes cluster configuration file with command: 


    bx cs cluster-config <your Bluemix Kubernetes cluster name >

    Example: bx cs cluster-config mycluster4YT

     When the download is finished, an export command is shown that you can use to set the path to your configuration file as an environment variable.

    p11

    b. Copy and paste the command from the previous step to set the environment variable and configure your CLI to run kubectl commands within your Kubernates cluster.

    export KUBECONFIG=<path_to_kubeconfig>




    Example:

    export KUBECONFIG=/home/ibmdemo/.bluemix/plugins/container-service/clusters/mycluster4YT/kube-config-prod-dal10-mycluster4YT.yml cli/clusters/my_cluster/kube-config-dev-mex01-my_cluster.yml

  5. Deploy containerized application to the Kubernetes cluster in Bluemix using Kubernetes CLI

    1. Deploy mongo container

    a. In your terminal window, enter the following two kubectl commands:

    kubectl run mongo –image=mongo –port=27017

    kubectl expose deployment mongo –type=NodePort

    Kubernetes has now created a deployment for the mongo database container, and exposed it as a service and updated the DNS server so the sample application can locate it.

    b. You can see the new service by issuing the following command to list it.

    kubectl get services

    2. Deploy node.js container

    a. Enter the following two kubetcl commands:

    kubectl run myemp –image=kavisuresh/employee –port=80

    kubectl expose deployment myemp –type=NodePort –port=80 –target-port=8888

    The myemp application is now deployed to the Kubernates Cluster.

    3. Access Kubernetes dashboard to view your deployment.

    a. Set a port number for Kubernets server with command

    kubectl proxy

    p12

    b. Open the following url in a web browser and you will get in the Kubernetes dashboard page.

    http://localhost:8001/ui

    p13

    As you can see the two containers deployed are up and running.

    p14

  6. Access the Employee Application

    The url of deployed Employee application running in myemp pod has a format like: http://myemp_Node_IP:myemp_Node_Port

     

    1. To get the myemp service Node IP and Port info.

    a. From the Kubernetes Dashboard, click on Nodes and write down the Node IP address (Fox example: myemp_Node_IP=169.47.237.153).

    p15

    b. Click on Services and write down the Node Port of the myemp pod (For example: myemp_Node_Port =32146).

    p16

    c. Enter the myemp application url (For example: http://169.47.237.153: 32146) in a web bowser, you can access the application.

    p17

    Now you can add, update, retrieve and delete employee data in this application (as described in detail in Kavisuresh’s recipe).

     

     

  7. Reference

    This recipe uses the sample application and database docker images and configurations created by Kavisuresh in her recipe published in December, 2016 (https://developer.ibm.com/recipes/tutorials/deploying-a-containerized-app-in-kubernetes-using-kubernetes-dashboard/).

Join The Discussion