Kubernetes Kompose

Kompose可以将 docker compose 的yaml文件转换成 kubernetes 使用的 yaml 文件

安装 参考 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

准备一个wordpress的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: {}

尝试 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$ 

修改 compose 文件的版本从 3.9 到 3

然后我们创建kubernetes资源

通过svc看一下应用

kubectl port-forward --namespace default service/wordpress 8000:8000

很容易发现,这里DB是没有生成 service 的,因为docker-compose.yml 文件里DB没有port

修改一下

可以看到这次生成了 db-service

Send a Message