Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Getting started with Kompose

August 2, 2017
Suraj Narwade
Related topics:
Kubernetes

    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

    • Debugging image mode with Red Hat OpenShift 4.20: A practical guide

    • EvalHub: Because "looks good to me" isn't a benchmark

    • SQL Server HA on RHEL: Meet Pacemaker HA Agent v2 (tech preview)

    • Deploy with confidence: Continuous integration and continuous delivery for agentic AI

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.