heidloff.net - Building is my Passion
Post
Cancel

Running the Sample App BlueChatter on Kubernetes

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

Essentially the docker-compose file needs to be converted to a Kubernetes yaml file. As 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 change in the file manually.
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’.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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.

1
2
3
$ 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.

1
2
3
4
5
$ 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.

1
2
3
$ kubectl create -f bluechatter.yaml
$ bx cs workers my_cluster # to get the public IP
$ kubectl describe service web # to get the port (NodePort)
Featured Blog Posts
Disclaimer
The postings on this site are my own and don’t necessarily represent IBM’s positions, strategies or opinions.
Trending Tags