kubernetes-kompose tool
Kompose can convert the yaml file of docker compose into the yaml file used by kubernetes
Installation reference https://kompose.io/installation/
curl -L https://github.com/kubernetes/kompose/releases/download/v1.22.0/kompose-linux-amd64 -o kompose
chmod +x kompose
sudo mv ./kompose /usr/local/bin/kompose
Prepare a docker-compose yml
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wordpress_data:/var/www/html
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
wordpress_data: {}
try convert
lizhe@ubuntu:~/works$ kompose convert
FATA Version 3.9 of Docker Compose is not supported. Please use version 1, 2 or 3
lizhe@ubuntu:~/works$
Modify the version of the compose file from 3.9 to 3
Then we create the kubernetes resource
check the application by svc
kubectl port-forward --namespace default service/wordpress 8000:8000
It is easy to find that the DB does not generate a service here, because docker compose There is no port in dB in YML file
Modify it
You can see that the DB service is generated this time