Microservices and Linux Containers

To get started developing microservices with Docker and Kubernetes, we’re going to leverage a set of developer tools called the Red Hat Container Development Kit (CDK). The CDK is free and is a small, self-contained VM that runs on a developer’s machine that contains Docker, Kubernetes, and a web console (actually, it’s Red Hat OpenShift, which is basically an enterprise-ready version of Kubernetes with other developer self-service and application lifecycle management features; but for this book we’ll just be using the Kubernetes APIs). OpenShift?

Red Hat OpenShift 3.x is an Apache v2, licensed, open source developer self-service platform OpenShift Origin that has been revamped to use Docker and Kubernetes. OpenShift at one point had its own cluster management and orchestration engine, but with the knowledge, simplicity, and power that Kubernetes brings to the world of container cluster management, it would have been silly to try and re-create yet another one. The broader community is converging around Kubernetes and Red Hat is all in with Kubernetes.

OpenShift has many features, but one of the most important is that it’s still native Kubernetes under the covers and supports role-based access control, out-of-the-box software-defined networking, security, logins, developer builds, and many other things. We mention it here because the flavor of Kubernetes that we’ll use for the rest of this book is based on OpenShift. We’ll also use the oc OpenShift command-line tools, which give us a better user experience and allow us to easily log in to our Kubernetes cluster and control which project into which we’re deploying. The CDK that we mentioned has both vanilla Kubernetes and OpenShift. For the rest of this book, we’ll be referring to OpenShift and Kubernetes interchangeably but using OpenShift.

Getting Started with the CDK

With the CDK, you can build, deploy, and run your microservices as Docker containers right on your laptop and then opt to deliver your microservice in a delivery pipeline through other application lifecycle management features inside of OpenShift or with your own tooling. The best part of the CDK is that it runs in a RHEL VM, which should match your development, QA, and production environments.

Instructions for installing the CDK can be found at http://red.ht/

1SVUp6g. There are multiple flavors of virtualization (e.g., Virtual‐

Microservices and Linux Containers

Box, VMWare, KVM) that you can use with the CDK. The installation documents for the CDK contain all of the details you need for getting up and running. To continue with the examples and idioms in the rest of this book, please install the CDK (or any other Docker/ Kubernetes local VM) following the instructions.

To start up the CDK, navigate to the installation directory and to the ./components/rhel/rhel-ose subdirectory and type the following:

$ vagrant up

This should take you through the provisioning process and boot the VM. The VM will expose a Docker daemon at tcp://10.1.2.2:2376 and the Kubernetes API at https://10.1.2.2:8443. We will next need to install the OpenShift oc command-line tools for your environment. This will allow us to log in to OpenShift/Kubernetes and manage our projects/namespaces. You could use the kubectl commands yourself, but logging in is easier with the oc login command, so for these examples, we’ll use oc. Download and install the oc client tools.

Once you’ve downloaded and installed both the CDK and the oc command-line tools, the last thing we want to do is set a couple of environment variables so our tooling will be able to find the OpenShift installation and Docker daemon. To do this, navigate to the ./ components/rhel/rhel-ose directory and run the following command:

$ eval "$(vagrant service-manager env docker)"

This will set up your environment variables. You can output the environment variables and manually configure them if you wish:

$ vagrant service-manager env docker export DOCKER_HOST=tcp://192.168.121.195:2376

export DOCKER_CERT_PATH=/home/john/cdk/components/rhel/rhel-ose/

.vagrant/machines/default/libvirt/.docker

export DOCKER_TLS_VERIFY=1 export DOCKER_MACHINE_NAME=081d3cd

We should now be able to log in to the OpenShift running in the

CDK:

$ oc login 10.1.2.2:8443 The server uses a certificate signed by an unknown authority.

You can bypass the certificate check, but any data you send to the server could be intercepted by others. Use insecure connections? (y/n): y

Authentication required for https://10.1.2.2:8443 (openshift) Username: admin Password:

Login successful.

You have access to the following projects and can switch between them with 'oc project <projectname>': * default

Using project "default".

Welcome! See 'oc help' to get started.

Let’s create a new project/namespace into which we’ll deploy our microservices:

$ oc new-project microservice-book Now using project "microservice-book" on server "https://10.1.2.2:8443&quot;.

You should be ready to go to the next steps!

Although not required to run these examples, installing the Docker CLI for your native developer laptop is useful as well. This will allow you to list Docker images and Docker containers right from your developer laptop as opposed to having to log in to the vagrant VM. Once you have the Docker CLI installed, you should be able to run Docker directly from your command-line shell (note, the environment variables previously discussed should be set up):

$ docker ps

$ docker images

results matching ""

    No results matching ""