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!
Join the DZone community and get the full member experience.
Join For Freesince 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.
-
i had to enter the name of my docker image, e.g. ‘registry.ng.bluemix.net/nheidloff/bluechatter_web’
-
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.
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)
Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments