Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      Developer Sandbox
      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

Getting started with Kompose

August 2, 2017
Suraj Narwade
Related topics:
Kubernetes

Share:

    We have written about Kompose earlier here , when it was as young as 0.1.0. This blog post will showcase where Kompose stands now.

    Kompose is a tool that converts a Docker Compose file to Kubernetes or OpenShift artifacts. Kompose was originally started as an onboarding tool for Kubernetes users by Skippbox (now part of Bitnami). It went on to receive early contributions from both Google and Red Hat.

    Kompose has graduated from the Kubernetes Incubator, we reached the epic milestone of 1.0.0, and so it's now officially part of the Kubernetes Community Project.

     Let's see what Kompose is all about! Here's a standard example that the Kubernetes community uses consisting of a web interface (Go) as well as a cluster of databases (Redis).

    Let's use an official Kompose example!

    version: "2"
    services:
    redis-master:
     image: grc.io/google_containers/redis:e2e
     ports:
     -"6379"
    redis-slave:
     image: gcr.io/google_samples/gb-redisslave:v1
     ports:
      - "6379"
      environment:
      - GET_HOSTS_FROM=dns
    frontend:
     image: gcr.io/google-samples/gb-frontend:v4
     ports:
     - 80:80
     environment:
     -GET_HOSTS_FROM=dns
     labels:
      kompose.service.type:LoadBalancer

    Features of Kompose:

    The following sections discuss the various features of Kompose:

    Deploying Kubernetes Artifacts Directly

    The following example demonstrates how you can run 'kompose up' to deploy an application to a kubernetes cluster. This example will use either *minishift* or *minikube* to test it locally.

    $ kompose up

    INFO We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. If you need a different kind of resource, use 'kompose convert' and 'kubectl create - f commands instead.

    INFO Deploying application in "default" namespace
    INFO Successfully created Service: frontend
    INFO Successfully created Service: redis-master
    INFO Successfully created Service: redis-slave
    INFO Successfully created Deployment: frontend
    INFO Successfully created Deployment: redis-master
    INFO Successfully created Deployment: redis-slave
    
    Your application has been deployed to Kubernetes. You can run 'kubetcl get deployment, svc, pods, pvc' for details.

    Generating Kubernetes Artifacts

    If you want to simply generate artifacts than deploying immediately, you can run 'kompose convert' as follows:

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

    You can deploy this later, when required, using:

    $ kubectl create -f frontend-service.yaml, redis-master-service.yaml, redis-slave-service.yaml, frontend-deployment.yaml, redis-master-deployment.yaml, redis-slave-deployment.yaml
    service "frontend" created
    service "redis-master" created

    Deploying/Generating OpenShift artifacts

    OpenShift is another distribution of Kubernetes and it is one of the supported providers of Kompose. You can deploy the artifacts on OpenShift by providing the command line argument '--provider':

    $ kompose up --provider openshift
    

    You can generate artifacts using:

    $ kompose convert --provider openshift
    

    Store output artifacts to a specific location

    In case, you need to store output artifacts to some location, use the command line argument '-o' as shown below.

    $ kompose convert -o out/
    INFO Kubernetes file "out/frontend-service.yaml" created
    INFO Kubernetes file "out/redis-master-service.yaml" created

    Replicas

    You can specify the number of replicas by using the command line argument '--replicas'.

    $ kompose convert --replicas=4
    

    Delete deployed manifests

    You can delete instanced artifacts like service, deployments etc. as follows:

    $ Kompose down
    INFO Deleting application id=n "default" namespace
    INFO Successfully deleted Service: frontend
    INFO Successfully deleted Service: redis-master
    INFO Successfully deleted Service: redis-alive
    INFO Successfully deleted Deployment: frontend
    INFO Successfully deleted Deployment: redis-master
    INFO Successfully deleted ployment: redis-slave

    Labels

    As of now, not all the Docker Compose keys can be mapped to Kubernetes artifacts. Hence, for service type and ingress, we have defined two types of Kompose specific labels as follows:

    'kompose.service.expose' defines if service needs to be made accessible from outside of a cluster
    labels:
     Kompose.service.expose: true
     Kompose.service.expose: "example.com"
    'kompose.service.type' defines types of services to be created
    labels:
    Kompse.service.type: nodeport # or clusterip or loadbalancer

    Kompose 1.0.0

    The following sections discuss the support provided by Kompose 1.0.0 for Docker build and push as well as for Docker Compose Version 3.

    Some Docker Compose files contain the 'build' key, which means that the Dockerfile file is in the code repository. When you do, 'docker-compose build' or 'docker-compose up', it is supposed to build the Docker image.

    Earlier, the `build` supported only the OpenShift provider and ignored the Kubernetes provider. In the 1.0.0 release, Kompose supports building container images for both Kubernetes and OpenShift providers.

    For example, in case our Docker compose file is:
       version: "3"
    services:
       foo:
           build: "./build"
           image" docker.io/foo/bar

    It would simply generate artifacts as follows (default value of '--build' flag is none):

     $ kompose convert
     INFO file "foo-service.yaml" created
     INFO file "foo-deployment.yaml created

    Whereas in the case of OpenShift provider, buildconfig gets generated using the following command:

    $ kompose convert --provider=openshift --build build-config
    INFO Buildconfig using git@github.com:surajnarwade/Kompose.git::master as a source.
    INFO file "foo-service.yaml" created
    INFO file "foo-deploymentconfig.yaml" created
    INFO file "foo-imagestream.yaml" created
    INFO file "foo-buildconfig.yaml" created
    

    When you run 'kompose up', the local building of images takes place and is pushed to the respective docker registry for which credentials are stored in the  '~/.docker/config.json' file in the user’s home directory. ('--build' flag is set to local)

    You can deploy it as follows:

    $ kompose up
    INFO Build key detected. Attempting to build and push image 'docker.io/foo/bar'
    INFO Building image 'docker.io/foo/bar' from directory 'build'
    INFO Image 'docker.io./foo/bar' from directory 'build' built successfully
    INFO Pushing image 'foo/bar:latest' to registry 'docker.io'
    INFO Attempting authentication credentials 'https://index.docker.io/v1/
    INFO Successfully pushed image 'foo/bar:latest' to registry 'docker.io'
    INFO We are going to create Kubernetes Deployments, Services and PersistentVolumeClaims for your Dockerized application. If you need a different kind of resources, use the 'kompose convert' and 'kubectl create -f' commands instead.
    INFO Deploying application in "default" namespace
    INFO Successfully created Service: foo
    INFO Successfully created Deployment: foo
    Your application has been deployed to Kubernetes. You can run 'kubectl get deployment, svc, pods, pvc' for details.
    

    In case you already have the required images, you need to disable building and pushing of the images using the '--build'parameter:

    $ kompose up --build none

    Docker Compose Version 3 support:

    As of 1.0.0, we provide support to Docker Compose Version 3.

    Here is a demonstration using our default example.(https://github.com/kubernetes/kompose/blob/master/examples/docker-compose-counter-v3.yaml)

    version: "3"
    services:
    web:
     image: tuna/docker-counter23
     ports:
       - "5000:5000"
     deploy:
       restart_policy:
         condition: any
     labels:
       kompose.service.type: Nodeport
    redis:
     image: redis:3.0
     deploy:
        replicas: 1
     ports:
       - "6379"

    Here's the other stuff we've added including bug fixes and new keys such as 'replicas', 'restart_policy', etc.

    Previously, we have to mention 'replicas' using '--replicas' flag, but now with Docker Compose version 3 support, we can mention replicas in Docker Compose file itself.

    Give it a try :)


    Download this Kubernetes cheat sheet for automating deployment, scaling and operations of application containers across clusters of hosts, providing container-centric infrastructure.

    Last updated: September 3, 2019

    Recent Posts

    • AI meets containers: My first step into Podman AI Lab

    • Live migrating VMs with OpenShift Virtualization

    • Storage considerations for OpenShift Virtualization

    • Upgrade from OpenShift Service Mesh 2.6 to 3.0 with Kiali

    • EE Builder with Ansible Automation Platform on OpenShift

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue