Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for migrating docker-compose solutions to kubernetes #820

Closed
wants to merge 1 commit into from

Conversation

kafnevod
Copy link

Hi
I'm using podman-compose to migrate docker-composite solutions to kubernetes via:

podman kube generate <podId> 

podman-compose uses the _ character as a delimiter when generating volume and container names.
For example, when starting a service stack
hello-python in POD:

# cd examples/hello-python
# podman-compose --in-pod hello-python up -d

we get a pod with container names hello-python_redis_1,``hello-python_web_1:

# podman pod ls --ctr-names
POD ID        NAME              STATUS      CREATED        INFRA ID    NAMES
6bc55962dc29  pod_hello-python  Running     2 minutes ago              hello-python_redis_1,hello-python_web_1

and volume name hello-python_redis

# podman volume ls | grep hello-python
hello-python_redis

After generating the kube- manifest

# podman kube generate pod_hello-python > ./kube.yml

and trying to run it,

# kubectl apply -f ./kube.yml

we receive an error message:

The Pod "podhello-python" is invalid: 
* spec.volumes[1].name: Invalid value: "hello-python_redis-pvc": a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name',  or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')
* spec.containers[0].volumeMounts[0].name: Not found: "hello-python_redis-pvc"
...

This pull request supports the --kubecompat flag, which when specified uses the - separator character when generating names of containers and volumes.
When podman-compose called with a flag --kubecompat

podman-compose --kubecompat --in-pod hello-python up -d

we get a pod with container names hello-python-redis-1, hello-python-web-1:

# podman pod ls --ctr-names
POD ID        NAME              STATUS      CREATED         INFRA ID    NAMES
87c28523698a  pod_hello-python  Running     59 minutes ago              hello-python-redis-1,hello-python-web-1

and volume name hello-python-redis

# podman volume ls | grep hello-python
hello-python-redis

After generating the kube- manifest

# podman kube generate pod_hello-python > ./kube.yml

and trying to run it,

# kubectl apply -f ./kube.yml

we get a correctly deployed pod:

# kubectl apply -f ./kube.yml 
pod/podhello-python created
# kubectl get pod/podhello-python -o wide
NAME              READY   STATUS    RESTARTS   AGE   IP           NODE     NOMINATED NODE   READINESS GATES
podhello-python   2/2     Running   0          47s   10.88.0.21   host-8              

The reason for using the _ character as a delimiter is not obvious to me.
Maybe it's worth using the - character as a default separator?

@kafnevod
Copy link
Author

In addition to using the - character as a separator for compatibility with kubernetes, the pull request lowercases container and volume names.

…ead '_' for volumes and containers names.

Signed-off-by: Alexey Kostarev <kaf@altlinux.org>
@p12tic
Copy link
Collaborator

p12tic commented Mar 8, 2024

Seems like useful addition to me.

@p12tic
Copy link
Collaborator

p12tic commented Mar 8, 2024

@kafnevod Is there a chance that you will use this feature in the future or was this just one off and you don't personally need it anymore?

@kafnevod
Copy link
Author

@kafnevod Is there a chance that you will use this feature in the future or was this just one off and you don't personally need it anymore?

@p12tic

I don't need this feature in the future

I found another approach - creating a separate python application podman-compose-to-kube.
This script provides conversion of a docker-compose solution to kubernetes.
Conversion to kubernetes POD and kubernetes Deployment is currently supported.
Conversion to Helm is planned in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants