I have a simple docker-compose file:
version: '3'
services:
auth-service:
image: <username>/auth-service:latest
ports:
- "8080:8080"
environment:
RUST_LOG: info
REDIS_HOST: redis-service
REDIS_PORT: 6379
RABBITMQ_HOST: rabbitmq-service
RABBITMQ_PORT: 5672
redis-service:
image: redis:latest
volumes:
- redis:/data
rabbitmq-service:
image: rabbitmq:latest
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
When I do podman generate kube
command, I get the following YAML for Redis:
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: "2023-11-26T12:58:11Z"
labels:
app: auth-app-redis-service-1-pod
name: auth-app-redis-service-1-pod
spec:
containers:
- args:
- redis-server
image: docker.io/library/redis:latest
name: auth-app-redis-service-1
volumeMounts:
- mountPath: /data
name: 1005b2fef1c47d55188a90e533bd0f4dca7a201e002db309fffd8367fd356dd5-pvc
volumes:
- name: 1005b2fef1c47d55188a90e533bd0f4dca7a201e002db309fffd8367fd356dd5-pvc
persistentVolumeClaim:
claimName: 1005b2fef1c47d55188a90e533bd0f4dca7a201e002db309fffd8367fd356dd5
And it's fine, except volumes. I want to apply it to Minikube, but I can't cause my claim doesn't exist. So why are they generated, and when and how should I apply them? Is it working only for Podman's Kubernetes backend? So, should I remove volumes for the Minikube setup? Appreciate.
UPD_1:
I changed compose to:
redis-service:
image: redis:latest
volumes: []
rabbitmq-service:
image: rabbitmq:latest
volumes: []
environment:
RABBITMQ_DEFAULT_USER: guest
RABBITMQ_DEFAULT_PASS: guest
And restart it, and podman still generates volumes in YAML. That's strange, but it's another topic.
UPD_2:
I get PVC manifests with the following script and am frustrated if this is the only way to achieve this (meaning manual generation). That's strange that podman itself knows that the container has a volume, but doesn't create PVC for it.
#!/bin/bash
mkdir -p k8s
for service in $(podman compose ps -q); do
service_name=$(podman inspect --format '{{ index .Config.Labels "com.docker.compose.service" }}' $service)
# Generate Kubernetes YAML for the container
podman generate kube $service > "k8s/$service_name.yaml"
# Check if the container has volumes
volumes=$(podman inspect --format '{{ range .Mounts }}{{ .Source }}{{ end }}' $service)
if [ -n "$volumes" ]; then
# Extract the volume name from the path
volume_name=$(echo "$volumes" | awk -F'/' '{print $(NF-1)}')
# Generate PVC YAML using 'podman kube' with the extracted volume name
podman kube generate $volume_name > "k8s/${service_name}_${volume_name}_pvc.yaml"
fi
done
UPD_3 (fantasy):
I expected something like podman kube generate my-container
or even podman kube generate my-compose-project
to get all the needed k8s kinds.