Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting docker-compose to a helm chart?

I have a docker-compose file containing 2 images to a security tool I am using. My challenge is to convert it into helm chart consisting of deployment.yaml and service.yaml. The docker-compose looks like this -

  version: '3'

  services:

  nginx:
    ports:
      - "80:80"
      - "443:443"
    environment:
      - NG_SERVER_NAME=192.168.1.228
    links:
      - tomcat8
    image: continuumsecurity/iriusrisk-prod:nginx-prod-ssl
    container_name: iriusrisk-nginx
    volumes:
      - "./cert.pem:/etc/nginx/ssl/star_iriusrisk_com.crt"
      - "./key.pem:/etc/nginx/ssl/star_iriusrisk_com.key"

  tomcat8:
    environment:
      - IRIUS_DB_URL=jdbc\:postgresql\://192.168.1.228\:5432/iriusprod?user\=iriusprod&password\=alongandcomplexpassword2523
      - IRIUS_EDITION=saas
      - IRIUS_EXT_URL=http\://192.168.1.228
      - grails_env=production
    image: continuumsecurity/iriusrisk-prod:tomcat8-2
    container_name: iriusrisk-tomcat8

There is a postgres server running too which I am able to convert into a helm chart and expose it to my ip (192.168.1.228) on port 5432. But for the iriusrisk and tomcat image which are linked to each other, I am not able to it figure out. This has been my solution for the deployment file for both.

deployment-tomcat.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat
  labels:
    app: {{ .Values.tomcat.app.name }}
spec:
  replicas: {{ .Values.tomcat.replicas }}
  selector:
    matchLabels:
      app: {{ .Values.tomcat.app.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.tomcat.app.name }}
    spec:
      {{- if .Values.tomcat.imagePullSecretsName }}
      imagePullSecrets:
      - name: {{ .Values.tomcat.imagePullSecretsName }}
      {{- end}}
      restartPolicy: Always
      serviceAccountName: {{ .Values.tomcat.serviceAccountName }}

      containers:
      - name: {{ .Values.tomcat.app.name }}
        image: "{{ .Values.tomcat.ImageName }}:{{ .Values.tomcat.ImageTag }}"
        container_name: iriusrisk-tomcat8
        imagePullPolicy: {{ .Values.tomcat.ImagePullPolicy }}
        ports:
        - containerPort: {{ .Values.tomcat.port }}
        env:
          - name: IRIUS_DB_URL
            value: jdbc\:postgresql\://192.168.1.228\:5432/iriusprod?user\=iriusprod&password\=alongandcomplexpassword2523
          - name: IRIUS_EDITION
            value: saas
          - name: IRIUS_EXT_URL
            value: http\://192.168.1.228
          - name: grails_env
            value: production

deployment-iriusrisk.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: iriusrisk
  labels:
    app: {{ .Values.iriusrisk.app.name }}
spec:
  replicas: {{ .Values.iriusrisk.replicas }}
  selector:
    matchLabels:
      app: {{ .Values.iriusrisk.app.name }}
  template:
    metadata:
      labels:
        app: {{ .Values.iriusrisk.app.name }}
    spec:
      {{- if .Values.iriusrisk.imagePullSecretsName }}
      imagePullSecrets:
      - name: {{ .Values.iriusrisk.imagePullSecretsName }}
      {{- end}}
      restartPolicy: Always
      serviceAccountName: {{ .Values.iriusrisk.serviceAccountName }}

      containers:
      - name: {{ .Values.iriusrisk.app.name }}
        image: "{{ .Values.iriusrisk.ImageName }}:{{ .Values.iriusrisk.ImageTag }}"
        container_name: iriusrisk-nginx
        imagePullPolicy: {{ .Values.iriusrisk.ImagePullPolicy }}
        ports:
        - containerPort: {{ .Values.iriusrisk.port }}
        env:
          - name: NG_SERVER_NAME
            value: "192.168.1.228"
        volumes: 
          - "./cert.pem:/etc/nginx/ssl/star_iriusrisk_com.crt"
          - "./key.pem:/etc/nginx/ssl/star_iriusrisk_com.key"

How should I go around solving this issue? I have looked at "linking" pods with each other but none of the solutions I tried worked. I am bit new to this hence I am still a bit confused about how to expose pods and connect to each other.

like image 582
Pranav Bhatia Avatar asked Feb 28 '20 04:02

Pranav Bhatia


People also ask

How do you convert Docker compose YAML to Kubernetes?

To convert the docker-compose. yml file to files that you can use with kubectl , run kompose convert and then kubectl apply -f <output file> . Your deployments are running in Kubernetes.

Is Docker compose like Kubernetes?

Kubernetes and Docker Compose are both container orchestration frameworks. Kubernetes runs containers over a number of computers, virtual or real. Docker Compose runs containers on a single host machine.

What is the difference between Docker image and Helm chart?

Helm is a package manager, it uses Docker images as part of charts. Helm charts have configs for Kubernetes and it uses Docker images which are built from Dockerfile.

How to build helm chart from Docker-Compose?

Important Note Katenary is a tool to help building Helm Chart from a docker-compose file, but docker-compose doesn’t propose as many features as what can do Kubernetes. So, we strongly recommend to use Katenary as a “bootstrap” tool and then to manually enhance the generated helm chart. You can download the binaries from the Release section.

How to create a helm chart in K8s?

You can run the docker-compose file to deploy the services and from the K8s YAML manifest you can write down the helm chart with the fields you want. In values.yaml you can add necessary based on your requirement which one you want to keep configurable.

How to migrate from Docker Compose to Kubernetes?

In a few steps, we'll take you from Docker Compose to Kubernetes. All you need is an existing docker-compose.yml file. Go to the directory containing your docker-compose.yml file. If you don't have one, test using this one.

What is docker compose YAML?

Our Docker Compose file, here called docker-compose.yaml, lays out the definitions that will run our services with Compose. A service in Compose is a running container, and service definitions contain information about how each container image will run.


2 Answers

The kompose tool now includes the ability to convert to Helm charts from docker-compose.yml files:

kompose convert -c

Check out the kompose Alternative Conversions documentation.

like image 171
Jeff Avatar answered Oct 24 '22 01:10

Jeff


From my current knowledge, there is no such tool is developed or published that converts helm-chart into docker-compose file. But the conversion from docker-compose to kubernetes resource manifests can be done by using tool like kompose (https://kompose.io).

like image 22
Shudipta Sharma Avatar answered Oct 24 '22 00:10

Shudipta Sharma