Skip to content

Latest commit

 

History

History
348 lines (254 loc) · 11.8 KB

getting-started.md

File metadata and controls

348 lines (254 loc) · 11.8 KB

Getting Started

  • TOC {:toc}

This is how you'll get started with Kompose!

There are three different guides depending on your container orchestrator as well as operating system.

For beginners and the most compatibility, follow the Minikube and Kompose guide.

Minikube and Kompose

In this guide, we'll deploy a sample docker-compose.yaml file to a Kubernetes cluster.

Requirements:

Start minikube:

If you don't already have a Kubernetes cluster running, minikube is the best way to get started.

$ minikube start
Starting local Kubernetes v1.7.5 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster

Download an example Docker Compose file, or use your own:

wget https://raw.githubusercontent.com/kubernetes/kompose/master/examples/docker-compose.yaml

Convert your Docker Compose file to Kubernetes:

Run kompose convert in the same directory as your docker-compose.yaml file.

$ kompose convert                           
INFO Kubernetes file "frontend-service.yaml" created         
INFO Kubernetes file "redis-master-service.yaml" created     
INFO Kubernetes file "redis-slave-service.yaml" created      
INFO Kubernetes file "frontend-deployment.yaml" created      
INFO Kubernetes file "redis-master-deployment.yaml" created  
INFO Kubernetes file "redis-slave-deployment.yaml" created 

Alternatively, you can convert and deploy directly to Kubernetes with kompose up.

$ kompose 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 Successfully created Service: redis          
INFO Successfully created Service: web            
INFO Successfully created Deployment: redis       
INFO Successfully created Deployment: web         

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

Access the newly deployed service:

Now that your service has been deployed, let's access it.

If you're using minikube you may access it via the minikube service command.

$ minikube service frontend

Otherwise, use kubectl to see what IP the service is using:

$ kubectl describe svc frontend
Name:                   frontend
Namespace:              default
Labels:                 service=frontend
Selector:               service=frontend
Type:                   LoadBalancer
IP:                     10.0.0.183
LoadBalancer Ingress:   123.45.67.89
Port:                   80      80/TCP
NodePort:               80      31144/TCP
Endpoints:              172.17.0.4:80
Session Affinity:       None
No events.

Note: If you're using a cloud provider, your IP will be listed next to LoadBalancer Ingress.

If you have yet to expose your service (for example, within GCE), use the command:

kubectl expose deployment frontend --type="LoadBalancer" 

To check functionality, you may also curl the URL.

$ curl http://123.45.67.89

Minishift and Kompose

In this guide, we'll deploy a sample docker-compose.yaml file to an OpenShift cluster.

Requirements:

Note: The service will NOT be accessible until you create an OpenShift route with oc expose. You must also have a virtualization environment setup. By default, minishift uses KVM.

Start minishift:

Minishift is a tool that helps run OpenShift locally using a single-node cluster inside of a VM. Similar to minikube.

$ minishift start
Starting local OpenShift cluster using 'kvm' hypervisor...
-- Checking OpenShift client ... OK
-- Checking Docker client ... OK
-- Checking Docker version ... OK
-- Checking for existing OpenShift container ... OK
...

Download an example Docker Compose file, or use your own:

wget https://raw.githubusercontent.com/kubernetes/kompose/master/examples/docker-compose.yaml

Convert your Docker Compose file to OpenShift:

Run kompose convert --provider=openshift in the same directory as your docker-compose.yaml file.

$ kompose convert --provider=openshift
INFO OpenShift file "frontend-service.yaml" created 
INFO OpenShift file "redis-master-service.yaml" created 
INFO OpenShift file "redis-slave-service.yaml" created 
INFO OpenShift file "frontend-deploymentconfig.yaml" created 
INFO OpenShift file "frontend-imagestream.yaml" created 
INFO OpenShift file "redis-master-deploymentconfig.yaml" created 
INFO OpenShift file "redis-master-imagestream.yaml" created 
INFO OpenShift file "redis-slave-deploymentconfig.yaml" created 
INFO OpenShift file "redis-slave-imagestream.yaml" created 

Alternatively, you can convert and deploy directly to OpenShift with kompose up --provider=openshift.

$ kompose up --provider=openshift       
INFO We are going to create OpenShift DeploymentConfigs, Services and PersistentVolumeClaims for your Dockerized application. 
If you need different kind of resources, use the 'kompose convert' and 'oc create -f' commands instead. 
 
INFO Deploying application in "myproject" namespace 
INFO Successfully created Service: frontend       
INFO Successfully created Service: redis-master   
INFO Successfully created Service: redis-slave    
INFO Successfully created DeploymentConfig: frontend 
INFO Successfully created ImageStream: frontend   
INFO Successfully created DeploymentConfig: redis-master 
INFO Successfully created ImageStream: redis-master 
INFO Successfully created DeploymentConfig: redis-slave 
INFO Successfully created ImageStream: redis-slave 

Your application has been deployed to OpenShift. You can run 'oc get dc,svc,is,pvc' for details.

Access the newly deployed service:

After deployment, you must create an OpenShift route in order to access the service.

If you're using minishift, you'll use a combination of oc and minishift commands to access the service.

Create a route for the frontend service using oc:

$ oc expose service/frontend
route "frontend" exposed

Access the frontend service with minishift:

$ minishift openshift service frontend --namespace=myproject
Opening the service myproject/frontend in the default browser...

You can also access the GUI interface of OpenShift for an overview of the deployed containers:

$ minishift console
Opening the OpenShift Web console in the default browser...

RHEL and Kompose

In this guide, we'll deploy a sample docker-compose.yaml file using both RHEL (Red Hat Enterprise Linux) and OpenShift.

Requirements:

Note: A KVM hypervisor must be setup in order to correctly use minishift on RHEL. You can set it up via the CDK Documentation under "Set up your virtualization environment".

Install Red Hat Development Suite:

Before we are able to use both minishift and kompose, DevSuite must be installed. A more concise installation document is available.

Change to root.

$ su -

Enable the Red Hat Developer Tools software repository.

$ subscription-manager repos --enable rhel-7-server-devtools-rpms
$ subscription-manager repos --enable rhel-server-rhscl-7-rpms

Add the Red Hat Developer Tools key to your system.

$ cd /etc/pki/rpm-gpg
$ wget -O RPM-GPG-KEY-redhat-devel https://www.redhat.com/security/data/a5787476.txt
$ rpm --import RPM-GPG-KEY-redhat-devel

Install Red Hat Development Suite and Kompose.

$ yum install rh-devsuite kompose -y

Start minishift:

Before we begin, we must do a few preliminary steps setting up minishift.

$ su -
$ ln -s /var/lib/cdk-minishift-3.0.0/minishift /usr/bin/minishift
$ minishift setup-cdk --force --default-vm-driver="kvm"
$ ln -s /home/$(whoami)/.minishift/cache/oc/v3.5.5.8/oc /usr/bin/oc

Now we may start minishift.

$ minishift start
Starting local OpenShift cluster using 'kvm' hypervisor...
-- Checking OpenShift client ... OK
-- Checking Docker client ... OK
-- Checking Docker version ... OK
-- Checking for existing OpenShift container ... OK
...

Download an example Docker Compose file, or use your own:

wget https://raw.githubusercontent.com/kubernetes/kompose/master/examples/docker-compose.yaml

Convert your Docker Compose file to OpenShift:

Run kompose convert --provider=openshift in the same directory as your docker-compose.yaml file.

$ kompose convert --provider=openshift
INFO OpenShift file "frontend-service.yaml" created 
INFO OpenShift file "redis-master-service.yaml" created 
INFO OpenShift file "redis-slave-service.yaml" created 
INFO OpenShift file "frontend-deploymentconfig.yaml" created 
INFO OpenShift file "frontend-imagestream.yaml" created 
INFO OpenShift file "redis-master-deploymentconfig.yaml" created 
INFO OpenShift file "redis-master-imagestream.yaml" created 
INFO OpenShift file "redis-slave-deploymentconfig.yaml" created 
INFO OpenShift file "redis-slave-imagestream.yaml" created 

Alternatively, you can convert and deploy directly to OpenShift with kompose up --provider=openshift.

$ kompose up --provider=openshift       
INFO We are going to create OpenShift DeploymentConfigs, Services and PersistentVolumeClaims for your Dockerized application. 
If you need different kind of resources, use the 'kompose convert' and 'oc create -f' commands instead. 
 
INFO Deploying application in "myproject" namespace 
INFO Successfully created Service: frontend       
INFO Successfully created Service: redis-master   
INFO Successfully created Service: redis-slave    
INFO Successfully created DeploymentConfig: frontend 
INFO Successfully created ImageStream: frontend   
INFO Successfully created DeploymentConfig: redis-master 
INFO Successfully created ImageStream: redis-master 
INFO Successfully created DeploymentConfig: redis-slave 
INFO Successfully created ImageStream: redis-slave 

Your application has been deployed to OpenShift. You can run 'oc get dc,svc,is,pvc' for details.

Access the newly deployed service:

After deployment, you must create an OpenShift route in order to access the service.

If you're using minishift, you'll use a combination of oc and minishift commands to access the service.

Create a route for the frontend service using oc:

$ oc expose service/frontend
route "frontend" exposed

Access the frontend service with minishift:

$ minishift openshift service frontend --namespace=myproject
Opening the service myproject/frontend in the default browser...

You can also access the GUI interface of OpenShift for an overview of the deployed containers:

$ minishift console
Opening the OpenShift Web console in the default browser...