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:

  1. Creation a Namespace(optional): this isolates the resources for the application

    in a kubernetes namespaces.

  2. Define a ConfigMap for configuration(optional): Stores non-sensitive configuration data.

  1. Define Secret for Sensitive Data: Securely store sensitive information like database passwords.

  1. Define Persistent Volume and Persistent Volume claim for the Database: For stateful application like databases.

  1. Define Deployment for the web-app and Database:

  1. Define Services for the web app and database.

Applying the Configuration

  1. Create the namespace:

kubectl apply -f namespace.yml

  1. Apply the ConfigMap and Secret:

kubectl apply -f configmap.yaml

kubectl apply -f secret.yaml

  1. Create the Persistent Volume and Persistent Volume Claim:

kubectl apply -f persistent-volume.yaml

kubectl apply -f persistent-volume-claim.yaml

  1. 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.