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

Kompose Up for OpenShift and Kubernetes

 

December 1, 2016
Dusty Mabe
Related topics:
ContainersDeveloper ToolsKubernetes
Related products:
Red Hat OpenShift Container Platform

Share:

    Introduction

    Kompose is a tool to convert from higher level abstractions of application definitions into more detailed Kubernetes artifacts. These artifacts can then be used to bring up the application in a Kubernetes cluster. What higher level application abstraction should kompose use?

    One of the most popular application definition formats for developers is the docker-compose.yml format for use with docker-compose that communicates with the docker daemon to bring up the application. Since this format has gained some traction we decided to make it the initial focus of Kompose to support converting this format to Kubernetes. So, where you would choose docker-compose to bring up the application in docker, you can use kompose to bring up the same application in Kubernetes, if that is your preferred platform.

    How Did We Get Here?

    At Red Hat, we had initially started on a project similar to Kompose, called Henge. We soon found Kompose and realized we had a lot of overlap in our goals so we decided to jump on board with the folks at Skippbox and Google who were already working on it.

    TL;DR We have been working hard with the Kompose and Kubernetes communities. Kompose is now a part of the Kuberetes Incubator and we also have added support in Kompose for getting up and running into your target environment in one command:

    $ kompose up 

    In this blog I'll run you through a simple application example and use kompose up to bring up the application on Kuberenetes and OpenShift.

    Getting an Environment

    It is now easier than ever to get up and running with Kubernetes and Openshift. If you want hosted you can spin up clusters in many cloud environments including Google Container Engine and OpenShift Online (with the developer preview). If you want a local experience for trying out Kubernetes/OpenShift on your laptop, there is the RHEL based CDK, (and the ADB for upstream components), oc cluster up, minikube, and the list goes on!

    Any way you look at it, there are many options for trying out Kubernetes and OpenShift these days. For this blog I'll choose to run on OpenShift Online, but the steps should work on any Openshift or Kubernetes environment.

    Once I had logged in to the openshift console at api.preview.openshift.com I was able to grab a token by visiting https://api.preview.openshift.com/oauth/token/request and clicking Request another token. It then will show you the oc command you can run to log your local machine into openshift online.

    I'll log in below and create a new project for this example blog:

    $ oc login --token=xxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --server=https://api.preview.openshift.com
    Logged into "https://api.preview.openshift.com:443" as "dustymabe" using the token provided.
    
    You don't have any projects. You can try to create a new project, by running
    
        $ oc new-project <projectname>
    
    $ oc new-project blogpost
    Now using project "blogpost" on server "https://api.preview.openshift.com:443".
    
    You can add applications to this project with the 'new-app' command. For example, try:
    
        $ oc new-app centos/ruby-22-centos7~https://github.com/openshift/ruby-hello-world.git
    
    to build a new hello-world application in Ruby.
    $

    Example Application

    Now that I have an environment to run my app in I need to give it an app to run! I took the example mlbparks application that we have been using for openshift for some time and converted the template to a more simplified definition of the application using the docker-compose.yml format:

    $ cat docker-compose.yml
    version: "2"
    services:
      mongodb:
        image: centos/mongodb-26-centos7
        ports:
          - '27017'
        volumes:
          - /var/lib/mongodb/data
        environment:
          MONGODB_USER: user
          MONGODB_PASSWORD: mypass
          MONGODB_DATABASE: mydb
          MONGODB_ADMIN_PASSWORD: myrootpass
      mlbparks:
        image: dustymabe/mlbparks
        ports:
          - '8080'
        environment:
          MONGODB_USER: user
          MONGODB_PASSWORD: mypass
          MONGODB_DATABASE: mydb
          MONGODB_ADMIN_PASSWORD: myrootpass

    Basically we have the mongodb service and then the mlbparks service which is backed by the dustymabe/mlbparks image. I simply generated this image from the openshift3mlbparks source code using s2i with the following command:

    $ s2i build https://github.com/gshipley/openshift3mlbparks openshift/wildfly-100-centos7 dustymabe/mlbparks 

    Now that we have our compose yaml file we can use kompose to bring it up. I am using kompose version v0.1.2 here:

    $ kompose --version
    kompose version 0.1.2 (92ea047)
    $ kompose --provider openshift up
    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[0000] Successfully created Service: mlbparks
    INFO[0000] Successfully created Service: mongodb
    INFO[0000] Successfully created DeploymentConfig: mlbparks
    INFO[0000] Successfully created ImageStream: mlbparks
    INFO[0000] Successfully created DeploymentConfig: mongodb
    INFO[0000] Successfully created ImageStream: mongodb
    INFO[0000] Successfully created PersistentVolumeClaim: mongodb-claim0
    
    Your application has been deployed to OpenShift. You can run 'oc get dc,svc,is,pvc' for details.

    Ok what happened here... We created an mlbparks Service, DeploymentConfig and ImageStream as well as a mongodb Service, DeploymentConfig, and ImageStream. We also created a PersistentVolumeClaim named mongodb-claim0 for the /var/lib/mongodb/data.

    Note: If you don't have Persistent Volumes the application will never come up because the claim will never get satisfied. If you want to deploy somewhere without Persistent Volumes then add --emptyvols to your command like kompose --provider openshift up --emptyvols.

    So let's see what is going on in OpenShift by querying from the CLI:

    $ oc get dc,svc,is,pvc
    NAME             REVISION                               REPLICAS       TRIGGERED BY
    mlbparks         1                                      1              config,image(mlbparks:latest)
    mongodb          1                                      1              config,image(mongodb:latest)
    NAME             CLUSTER-IP                             EXTERNAL-IP    PORT(S)     AGE
    mlbparks         172.30.67.72                           <none>         8080/TCP    4m
    mongodb          172.30.111.51                          <none>         27017/TCP   4m
    NAME             DOCKER REPO                            TAGS           UPDATED
    mlbparks         172.30.47.227:5000/blogpost/mlbparks   latest         4 minutes ago
    mongodb          172.30.47.227:5000/blogpost/mongodb    latest         4 minutes ago
    NAME             STATUS                                 VOLUME         CAPACITY   ACCESSMODES   AGE
    mongodb-claim0   Bound                                  pv-aws-adbb5   100Mi      RWO           4m

    and the web console looks like:

    One final thing we have to do is set it up so that we can connect to the service (i.e. the service is exposed to the outside world). On OpenShift, we need to expose a route. This will be done for us automatically in the future (follow along at #140), but for now the following command will suffice:

    $ oc expose svc/mlbparks
    route "mlbparks" exposed
    $ oc get route mlbparks
    NAME       HOST/PORT                                          PATH      SERVICE         TERMINATION   LABELS
    mlbparks   mlbparks-blogpost.44fs.preview.openshiftapps.com             mlbparks:8080                 service=mlbparks

    For me this means I can now access the mlbparks application by pointing my web browser to mlbparks-blogpost.44fs.preview.openshiftapps.com.

    Let's try it out:

    Success!
    Dusty

    Last updated: February 23, 2024

    Recent Posts

    • GuideLLM: Evaluate LLM deployments for real-world inference

    • Unleashing multimodal magic with RamaLama

    • Integrate Red Hat AI Inference Server & LangChain in agentic workflows

    • Streamline multi-cloud operations with Ansible and ServiceNow

    • Automate dynamic application security testing with RapiDAST

    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

    Red Hat legal and privacy links

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

    Report a website issue