Deploying to Kubernetes with the IBM Cloud Developer Tools CLI

The recent release of the IBM Cloud Developer Tools CLI (formerly referred to as the Bluemix CLI dev plugin) is packed full of new features, including enablement for existing projects, productivity enhancements, bug fixes, and what I’d like to focus on in this post, support for Kubernetes deployments.

What is Kubernetes?

For those not yet familiar, Kubernetes is an open source platform designed to automate deploying, scaling, and operating application containers. This lets you package your application(s) within Docker images and deploy/scale applications quickly and easily in a self healing environment. This is the backbone for the IBM Container service, as well as the IBM Cloud Private offering. In this post, we will focus on Kubernetes deployment to public IBM Cloud environment.

Kubernetes Support?

In general, the IBM Cloud Developer Tools CLI enables rapid application development and deployment by generating template applications that you can run immediately or customize as the starter for your own solutions.

For the CLI dev extension, adding support for Kubernetes environments means two things:

In addition to generating starter application code and Dockerfile/CloudFoundry assets (which were already generated prior to this release), the code generators used by the dev CLI and web console will now generate files to aid deployment into Kubernetes environments. Specifically, the templates now generate Helm charts that describe the application’s initial Kubernetes deployment configuration, and are easily extended to create multi-image or complex deployments as needed.

The deploy-image-target value specifies the target where your Docker image should be pushed. If you’re logged in and targeting an application running on the Bluemix Container Service, this should be in the format registry.<Bluemix Region>.bluemix.net/<Container Registry Namespace>/<App-Name>. A sample in this format would be “registry.ng.bluemix.net/andrewtrice/my-test-application”. You can also specify the deployment image target as just an application name (no spaces), such as my-test-application. In this case, the deploy command will not upload to a container registry, instead it will push to the environment defined within your KUBECONFIG environment variable, such as a local MiniKube cluster.

If you are logged into IBM Cloud, the ibm-cluster value specifies the name of your Kubernetes cluster on the IBM Container Service that will be targeted for deployment. If you are not logged in, this will be ignored and assume the deploy-image-target is pointing at a MiniKube or IBM Cloud public environment. If you do not already have a Kubernetes cluster on IBM Cloud, you can create one on the IBM Container Service.

When targeting Kubernetes on the IBM Container Service, the deploy command will:

Build and upload the Docker image of your application to the IBM Container Registry

Download the configuration of your Kubernetes cluster on the IBM Cloud

Perform a deployment to your Kubernetes cluster using the generated Helm chart.

Note: If you haven’t setup a Helm tiller server in your Kubernetes cluster, that’s ok. The deploy command will run “helm init” for you, if it is not already configured.

Set your deployment preferences as CLI arguments

If you don’t want to change any configuration files, you can add -t container arguments to your CLI invocation like so:

[code]bx dev deploy -t container[/code]

This will instruct the deploy command to target the Kubernetes environment. When you invoke the deploy command, you’ll be prompted for additional input like the sample below:

[code]$ bx dev deploy -t container

The container deployment image name for the deployment of this project will be:
registry.ng.bluemix.net/andrewtrice/my-test-application

? Press [Return] to accept this, or enter a new value now>

The IBM cluster name for the deployment of this project will be:
mycluster

? Press [Return] to accept this, or enter a new value now>[/code]

The first value that you are prompted for is the deployment image target. This is functionally equivalent to the deploy-image-target cli-config value described above. The second value you will be prompted for is the name of your cluster on the IBM Cloud.

Your responses to these prompts will be persisted so the values can be easily reused on future deployments. Both of these values could also be passed as the --deploy-image-target and --ibm-cluster command line arguments.

Getting started

This sounds great, right? So, now you’re probably wondering “How do I get started?” The first thing you need to do is install the IBM Cloud Developer Tools CLI, and it’s prerequisite dependencies. While this might sound like a lot of legwork, it’s really not.

If you’re on MacOS or Linux, just open up a terminal and run the following command:

[code]curl -sL https://ibm.biz/idt-installer | bash[/code]

If you’re on Windows 10, open Windows PowerShell by right-clicking and select “Run as Administrator” and run the following command:

This will install the Bluemix CLI, all necessary extensions, git, docker, kubectl, and helm if you don’t already have them installed. If you’re curious about what this installer is doing “under the covers”, you can check out the installation scripts at https://github.com/IBM-Bluemix/ibm-cloud-developer-tools

Next, make sure you create a namespace for the Bluemix Container Registry by running the namespace-add command:

[code]bx cr namespace-add mynamespace[/code]

Now you’re ready to generate a project! You can generate a new project that contains Kubernetes support by simply running the bx dev create command, or run bx dev enable to create Kubernetes deployment files for an existing Node, Java, Python, or Swift project.

To benefit from the reuse and consistency microservice APIs offer, other developers will need guidance to use your APIs correctly. With annotations defined in the MicroProfile OpenAPI specification from Java EE, it's easy to generate clear documentation.

The IBM Hybrid Cloud Team has authored a tutorial that will guide you through the steps required to set up and install a Jenkins server and deploy a sample Node and React application on IBM Cloud Kubernetes Service.