Kompose Documentation

repository·main·Indexed 27 days ago

https://github.com/kubernetes/kompose

Kompose is a tool that translates Docker Compose Specification files into Kubernetes or OpenShift resource manifests. It features a three-stage pipeline consisting of a Loader, Transformer, and Outputter to convert Compose files into manifests such as Deployments and Services. The tool supports shell autocompletion for Bash, Zsh, and Fish, and provides a mapping reference for converting container configurations, networking, and storage from Compose to Kubernetes.

Tokens
11.3K
Snippets
39
Records
73
Agent score
92%

What's inside Kompose

  1. Understand the Kompose internal architecture

    main

    Kompose operates through a three-stage pipeline designed with well-defined interfaces to allow for extensibility. The stages are:

    1. Loader: Reads input files (currently supporting Docker Compose v1 and v2) and converts them into an internal KomposeObject representation.
    2. Transformer: Takes the KomposeObject and converts it into target Kubernetes or OpenShift objects.
    3. Outputter: Takes the transformed objects and executes an action, such as printing them to stdout or deploying them directly to a cluster.
  2. Set up a local development environment for Kompose

    main

    To develop Kompose, fork the main repository on GitHub and clone it into your $GOPATH/src/github.com/kubernetes/kompose directory. This ensures compatibility with Go's workspace expectations. You should also add the original repository as an upstream remote to keep your fork in sync.

    git clone https://github.com/$YOUR_GITHUB_USERNAME/kompose.git $GOPATH/src/github.com/kubernetes/kompose
    cd $GOPATH/src/github.com/kubernetes/kompose
    git remote add upstream 'https://github.com/kubernetes/kompose'
  3. Convert Docker Compose files to Kubernetes using Minikube

    main

    To deploy a Docker Compose application to a local Kubernetes cluster using Minikube, follow these steps:

    1. Start Minikube: Ensure you have a running cluster.
      minikube start
    2. Prepare Compose file: Ensure your compose.yaml is in your working directory.
    3. Convert to Kubernetes: Run the conversion command to generate Kubernetes manifest files.
      kompose convert
    4. Deploy: Use kubectl apply to create the generated resources in your cluster.
    5. Access Service: Use minikube service to open the service in your browser, or use kubectl describe svc <service-name> to find the IP address.
  4. Deploy Spring Boot applications using Fabric8 Maven Plugin and Kompose

    main

    You can deploy a Spring Boot Java application to Kubernetes or OpenShift by integrating the Fabric8 Maven Plugin with Kompose. This workflow allows you to use a Docker Compose file as the source for your Kubernetes deployment via Maven.

    Prerequisites

    • Linux, macOS, or Windows
    • JDK 1.7+
    • Maven 3.x+
    • Kompose installed

    Setup Steps

    1. Initialize Fabric8 Maven Plugin: Run the setup command to prepare your project:

      mvn io.fabric8:fabric8-maven-plugin:3.5.28:setup
    2. Install Kompose via Maven: Use the following command to install kompose on your host machine through Maven:

      mvn fabric8:install
    3. Configure pom.xml: Add the Fabric8 Maven Plugin configuration to your pom.xml. You must specify the path to your Compose file using the <composeFile> tag.

    4. Deploy: Ensure your Kubernetes/OpenShift cluster (or Minikube/Minishift) is running, then execute:

      mvn fabric8:deploy
    <plugin>
      <groupId>io.fabric8</groupId>
      <artifactId>fabric8-maven-plugin</artifactId>
      <configuration>
        <composeFile>path for docker compose file</composeFile>
      </configuration>
      <executions>
        <execution>
          <goals>
            <goal>resource</goal>
            <goal>build</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  5. Install Kompose via binary

    main

    The preferred installation method is downloading the binary from the latest GitHub release.

    Linux and macOS: Download the appropriate architecture binary, make it executable, and move it to your PATH (e.g., /usr/local/bin/).

    Windows: Download the .exe from the GitHub release page and add the binary to your PATH.

    # Linux
    curl -L https://github.com/kubernetes/kompose/releases/download/v1.38.0/kompose-linux-amd64 -o kompose
    
    # macOS
    curl -L https://github.com/kubernetes/kompose/releases/download/v1.38.0/kompose-darwin-amd64 -o kompose
    
    chmod +x kompose
    sudo mv ./kompose /usr/local/bin/kompose
  6. Convert Docker Compose files to OpenShift using Minishift

    main

    To deploy a Docker Compose application to an OpenShift cluster using Minishift, follow these steps:

    1. Start Minishift: Start your local OpenShift cluster.
      minishift start
    2. Convert to OpenShift: Use the --provider=openshift flag to generate OpenShift-specific manifests (like DeploymentConfigs and ImageStreams).
      kompose convert --provider=openshift
    3. Deploy: Use kubectl apply to create the resources in the OpenShift cluster.
    4. Expose Service: OpenShift requires a route to be created before the service is accessible.
      oc expose service/frontend
    5. Access Service: Use minishift openshift service <service-name> to open the service in your browser, or minishift console to open the OpenShift Web console.