Docker compose to Kubernetes
This article is to migrate from Docker compose to kubernetes involves the docker compose configuration into kubernetes resource definitions. Here a step-by-step
example with commments explaining the YAML files included:
Examples Scearios:
lets assume we have a docker compose file that defines a simple web application
with a single service( a Python Flask app) and a Database(PostgreSQL).
Docker Compose File(docker-compose.yml):
Migration to kubernetes:
Creation a Namespace(optional): this isolates the resources for the application
in a kubernetes namespaces.
Define a ConfigMap for configuration(optional): Stores non-sensitive configuration data.
- Define Secret for Sensitive Data: Securely store sensitive information like database passwords.
- Define Persistent Volume and Persistent Volume claim for the Database: For stateful application like databases.
- Define Deployment for the web-app and Database:
- Define Services for the web app and database.
Applying the Configuration
- Create the namespace:
kubectl apply -f namespace.yml
- Apply the ConfigMap and Secret:
kubectl apply -f configmap.yaml
kubectl apply -f secret.yaml
- Create the Persistent Volume and Persistent Volume Claim:
kubectl apply -f persistent-volume.yaml
kubectl apply -f persistent-volume-claim.yaml
- Deploy the web application and database:
kubectl apply -f web-deployment.yaml
kubectl apply -f db-deployment.yaml
5. Create the services
kubectl apply -f web-service.yaml
kubectl apply -f db-service.yaml
This setup provides a basic migration path from Docker compose to Kubernetes.