Skip to content

support multiple containers in a pod#1394

Merged
hangyan merged 4 commits intokubernetes:masterfrom
tk42:master
Jul 8, 2021
Merged

support multiple containers in a pod#1394
hangyan merged 4 commits intokubernetes:masterfrom
tk42:master

Conversation

@tk42
Copy link
Copy Markdown
Contributor

@tk42 tk42 commented Jul 3, 2021

As is mentioned in #1012, kompose convert creates each service as its own pod with single container.

--multiple-container-mode enables creating multiple containers in a pod. This function is experimental.

In case that such many changes might destroy the behavior known as before, so a temporary argument --multiple-container-mode switches its behavior. If the argument wasn't specified, kompose converts your docker-compose.yml along with keeping the behavior before. If no problems are reported after released as stable, this development mode is better to be merged for readable codes.

How it works

In your docker-compose.yml, add kompose.service.group={identifier grouped by pods} in labels to specify the containers in the same pod.

version: "3"

services:
  nginx:
    image: nginx
    depends_on:
      - logs
    labels: 
      - kompose.service.group=sidecar
    environment:
      - HOGE=TEST
    volumes:
      - "/var/log/nginx"

  logs:
    image: busybox
    command: ["sh","-c","while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done"]
    labels: 
      - kompose.service.group=sidecar
    env_file:
      - .env
    volumes:
      - "/var/log/nginx"

add --multiple-container-mode option in kompose convert

kompose convert docker-compose.yml --multiple-container-mode

then, you'll get a yaml for deployment as follows

apiVersion: v1
items:
  - apiVersion: apps/v1
    kind: Deployment
    metadata:
      annotations:
        kompose.service.group: sidecar
      creationTimestamp: null
      labels:
        io.kompose.service: sidecar
      name: sidecar
    spec:
      replicas: 1
      selector:
        matchLabels:
          io.kompose.service: sidecar
      strategy:
        type: Recreate
      template:
        metadata:
          annotations:
            kompose.service.group: sidecar
          creationTimestamp: null
          labels:
            io.kompose.service: sidecar
        spec:
          containers:
            - env:
                - name: HOGE
                  value: TEST
              image: nginx
              name: nginx
              resources: {}
              volumeMounts:
                - mountPath: /var/log/nginx
                  name: nginx-claim0
            - args:
                - sh
                - -c
                - while true; do cat /var/log/nginx/access.log /var/log/nginx/error.log; sleep 30; done
              env:
                - name: HOGEHOGE
                  valueFrom:
                    configMapKeyRef:
                      key: HOGEHOGE
                      name: env
              image: busybox
              name: logs
              resources: {}
              volumeMounts:
                - mountPath: /var/log/nginx
                  name: logs-claim0
          restartPolicy: Always
          volumes:
            - name: nginx-claim0
              persistentVolumeClaim:
                claimName: nginx-claim0
            - name: logs-claim0
              persistentVolumeClaim:
                claimName: logs-claim0
    status: {}
  - apiVersion: v1
    data:
      HOGEHOGE: TEST
    kind: ConfigMap
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: sidecar-env
      name: env
  - apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: logs-claim0
      name: logs-claim0
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 100Mi
    status: {}
kind: List
metadata: {}

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Jul 3, 2021
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @tk42!

It looks like this is your first PR to kubernetes/kompose 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kompose has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot requested review from kadel and ngtuna July 3, 2021 00:30
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tk42
To complete the pull request process, please assign sebgoa after the PR has been reviewed.
You can assign the PR to them by writing /assign @sebgoa in a comment when ready.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Jul 3, 2021
@tk42
Copy link
Copy Markdown
Contributor Author

tk42 commented Jul 3, 2021

/check-cla

@tk42
Copy link
Copy Markdown
Contributor Author

tk42 commented Jul 3, 2021

/help

@hangyan
Copy link
Copy Markdown
Contributor

hangyan commented Jul 3, 2021

@tk42 You can follow the links and sign the CLA

@tk42
Copy link
Copy Markdown
Contributor Author

tk42 commented Jul 3, 2021

@hangyan
I signed up a CLA account and received its verification with email as well.
I found my commits contained wrong user.name in git config so I forced push those commits in correct user.name, but still failed. I have no clue.

P.S. I overlooked an email from HelloSign service.

@tk42
Copy link
Copy Markdown
Contributor Author

tk42 commented Jul 3, 2021

/check-cla

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 3, 2021
@hangyan
Copy link
Copy Markdown
Contributor

hangyan commented Jul 4, 2021

cla seems works now

@hangyan
Copy link
Copy Markdown
Contributor

hangyan commented Jul 7, 2021

@tk42 This looks great, i'm reviewing this when i'm free. You may need to update related docs about this change(https://github.com/kubernetes/kompose/blob/master/docs/user-guide.md, the Labels part)

@hangyan
Copy link
Copy Markdown
Contributor

hangyan commented Jul 8, 2021

Looks all good!

@hangyan hangyan merged commit deb00f3 into kubernetes:master Jul 8, 2021
@hangyan
Copy link
Copy Markdown
Contributor

hangyan commented Jul 8, 2021

Thanks @tk42. This is great

@tk42
Copy link
Copy Markdown
Contributor Author

tk42 commented Jul 8, 2021

Thanks for the reviewing:bow:

@joaoborsoi
Copy link
Copy Markdown

--multiple-container-mode option is not at the user user guide

For me, it would be greate if the kompose.service.export could be used to setup multiples rules on the ingress config

@hangyan
Copy link
Copy Markdown
Contributor

hangyan commented Dec 1, 2021

Yeah, will update the docs...

@tpanza
Copy link
Copy Markdown

tpanza commented Nov 5, 2022

@tk42 is it intended for --multiple-container-mode to not work when using --provider openshift?

@tk42
Copy link
Copy Markdown
Contributor Author

tk42 commented Nov 7, 2022

@tpanza

@tk42 is it intended for --multiple-container-mode to not work when using --provider openshift?

No it's not. In this PR transformer is located at pkg/transformer/kubernetes.

jonas-l added a commit to jonas-l/kompose that referenced this pull request Mar 21, 2023
The user guide contains a list of labels which can be used to change the output of `kompose`. `kompose.service.group` is listed as available label, however, it has no effect unless an additional `--multiple-container-mode` flag (which was mentioned in [original PR][1]) is passed.

[1]: kubernetes#1394
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants