Skip to content

Instantly share code, notes, and snippets.

@surajssd
Last active November 13, 2016 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save surajssd/be637bc69ed6460e7f1c829ec0faf34c to your computer and use it in GitHub Desktop.
Save surajssd/be637bc69ed6460e7f1c829ec0faf34c to your computer and use it in GitHub Desktop.
OpenCompose services.yml

The services.yml file

$ cat services.yml 
version: "0.2"

services:
    frontend:
        image: docker.io/surajd/frontend:v1
        ports:
            - 8080:8080
        type: external

    backend:
        image: docker.io/surajd/backend:v1
        ports:
            - 3000:3000
        environment:
            MONGODB_PASSWORD: pass
            MONGODB_USER: user
            MONGODB_DATABASE: db
            MONGODB_SERVER: mongodb:27017

    mongodb:
        image: tomaskral/mongodb-centos7
        ports:
            - 27017:27017
        volumes:
            - db-store:/var/lib/mongodb/data
        environment:
            MONGODB_PASSWORD: pass
            MONGODB_USER: user
            MONGODB_DATABASE: db
            MONGODB_ADMIN_PASSWORD: root

volumes:
    db-store:
        size: "2Gi"
        mode: ReadWriteOnce

pv definition to be used for this example

$ cat local-pv.yml 
apiVersion: "v1"
kind: "PersistentVolume"
metadata:
  name: "pv0001"
spec:
  capacity:
    storage: "5Gi"
  accessModes:
    - "ReadWriteOnce"
  persistentVolumeReclaimPolicy: Recycle
  hostPath:
    path: /tmp/pv0001

Create a pv

$ kubectl create -f local-pv.yml 
persistentvolume "pv0001" created

Deploy application

$ kompose --opencompose services.yml up                              
We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. 
If you need different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead. 

INFO[0000] Successfully created service: frontend       
INFO[0000] Successfully created service: backend        
INFO[0000] Successfully created service: mongodb        
INFO[0000] Successfully created persistentVolumeClaim: db-store 
INFO[0000] Successfully created deployment: frontend    
INFO[0000] Successfully created deployment: backend     
INFO[0000] Successfully created deployment: mongodb     

Your application has been deployed to Kubernetes. You can run 'kubectl get deployment,svc,pods,pvc' for details.

All deployments are created and in desired state

 $ kubectl get deployments
NAME       DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
backend    1         1         1            1           2m
frontend   1         1         1            1           2m
mongodb    1         1         1            1           2m

All services have been created

$ kubectl get svc
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)     AGE
backend      10.0.0.247   <none>        3000/TCP    2m
frontend     10.0.0.217   <pending>     8080/TCP    2m
kubernetes   10.0.0.1     <none>        443/TCP     15d
mongodb      10.0.0.166   <none>        27017/TCP   2m

All pods are running as well

$ kubectl get pods -o wide
NAME                        READY     STATUS    RESTARTS   AGE       IP           NODE
backend-1215184120-hfji7    1/1       Running   0          3m        172.17.0.4   minikube
frontend-2479999252-tpzff   1/1       Running   0          3m        172.17.0.5   minikube
mongodb-254926443-c1rba     1/1       Running   0          3m        172.17.0.3   minikube
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment