Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Running the Sample BlueChatter App on Kubernetes

DZone's Guide to

Running the Sample BlueChatter App on Kubernetes

Now that Bluemix has started support for Kubernetes, let's go through what it takes to convert docker-compose files into YAML and build your containers. Orchestrate away!

· Cloud Zone
Free Resource

Are you joining the containers revolution? Start leveraging container management using Platform9's ultimate guide to Kubernetes deployment.

Since last month, Bluemix has started to support Kubernetes (beta), which many people consider the de-facto standard for container orchestration. Some of the older and simpler Bluemix sample applications use docker-compose. Below is a description of how to run those examples on Kubernetes.

Essentially, the docker-compose file needs to be converted to a Kubernetes YAML file. For example, I use the chat application BlueChatter. The sample is a Node.js application that leverages Redis to store session data. The file docker-compose.yml defines the two containers: the ports and links.

In order to create the Kubernetes configuration file, I’ve tried an open source project Kompose (Kubernetes + Compose). When you run it, four files are created, two for the deployments and two for the services. For a quick introduction to these terms, watch this video. I’ve merged everything into one file.

There were only two things I had to manually change in the file.

  1. I had to enter the name of my Docker image, e.g. ‘registry.ng.bluemix.net/nheidloff/bluechatter_web’

  2. In order to expose the web application via a public IP address, I defined a public port for the ‘web’ service via NodePort.

Here is a screenshot of the Kubernetes dashboard.

kube-bluechatter

Here is the Kubernetes file ‘bluechatter.yaml’.

apiVersion: extensions/v1beta1
kind: Deployment
metadata:  
  name: redis
spec:
  replicas: 1  
  template:
    metadata:      
      labels:
        bluechatter: redis
    spec:
      containers:
      - image: redis
        name: redis        
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:  
  labels:
    bluechatter: redis
  name: redis
spec:
  clusterIP: None
  ports:
  - name: headless
    port: 55555
    targetPort: 0
  selector:
    bluechatter: redis
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:  
  name: web
spec:
  replicas: 1
  template:
    metadata:
      labels:
        bluechatter: web
    spec:
      containers:
      - name: web
        image: registry.ng.bluemix.net/nheidloff/bluechatter_web
        ports:
        - containerPort: 80
        - containerPort: 8080
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  labels:
    bluechatter: web
  name: web
spec:
  type: NodePort
  ports:
  - name: "80"
    port: 80
    nodePort: 30072  
  selector:
    bluechatter: web


Run these commands to create and configure a cluster.

$ bx cs cluster-create --name my_cluster
$ bx cs workers my_cluster # wait and repeat until state is 'deployed'
$ bx cs cluster-config my_cluster # copy and paste the 'export ...' line


Run these commands to build the containers of the sample.

$ git clone https://github.com/IBM-Bluemix/bluechatter.git
$ cd bluechatter
$ docker-compose build
$ docker tag bluechatter_web registry.ng.bluemix.net/nheidloff/bluechatter_web
$ docker push registry.ng.bluemix.net/nheidloff/bluechatter_web


Run these commands to deploy the sample application.

$ kubectl create -f bluechatter.yaml
$ bx cs workers my_cluster # to get the public IP
$ kubectl describe service web # to get the port (NodePort)


Using Containers? Read our Kubernetes Comparison eBook to learn the positives and negatives of Kubernetes, Mesos, Docker Swarm and EC2 Container Services.

Topics:
cloud ,ibm bluemix ,kubernetes ,container orchestration ,tutorial

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}