繁体   English   中英

将 docker-compose.yml 文件转换为 kubernetes

[英]convert docker-compose.yml file to kubernetes

我正在使用运行以下命令的 kompose 将 docker-compose 文件转换为 kubernetes:

$kompose 转换 -f docker-compose.yml -o kubernetes_image.yaml

命令完成后,输出如下。

WARN Volume mount on the host "/usr/docker/adpater/dbdata" isn't supported - ignoring path on the host
INFO Network integration is detected at Source, shall be converted to equivalent NetworkPolicy at Destination
WARN Volume mount on the host "/usr/docker/adpater/license.json" isn't supported - ignoring path on the host
WARN Volume mount on the host "/usr/docker/adpater/certificates/ssl.crt" isn't supported - ignoring path on the host
WARN Volume mount on the host "/usr/docker/adpater/certificates/ssl.key" isn't supported - ignoring path on the host
WARN Volume mount on the host "/usr/docker/adpater/server.xml" isn't supported - ignoring path on the host
INFO Network integration is detected at Source, shall be converted to equivalent NetworkPolicy at Destination

要将转换后的文件推送到 kubernetes 我运行以下命令:

$kubectl apply -f kubernetes_image.yaml

NAME                      READY   STATUS             RESTARTS   AGE
mysql-557dd849c8-bsdq7    1/1     Running            1          17h
tomcat-7cd65d4556-spjbl   0/1     CrashLoopBackOff   76         18h

如果我运行: $ kubectl describe pod tomcat-7cd65d4556-spjbl 我收到以下消息:

Last State:     Terminated
      Reason:       ContainerCannotRun
      Message:      OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused \"rootfs_linux.go:58: mounting \\\"/usr/docker/adapter/server.xml\\\" to rootfs \\\"/var/lib/docker/overlay2/a6df90a0ef4cbe8b2a3fa5352be5f304cd7b648fb1381492308f0a7fceb931cc/merged\\\" at \\\"/var/lib/docker/overlay2/a6df90a0ef4cbe8b2a3fa5352be5f304cd7b648fb1381492308f0a7fceb931cc/merged/usr/local/tomcat/conf/server.xml\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
      Exit Code:    127
      Started:      Sun, 31 May 2020 13:35:00 +0100
      Finished:     Sun, 31 May 2020 13:35:00 +0100
    Ready:          False
    Restart Count:  75
    Environment:    <none>
    Mounts:
      /run/secrets/rji_license.json from tomcat-hostpath0 (rw)
      /usr/local/tomcat/conf/server.xml from tomcat-hostpath3 (rw)
      /usr/local/tomcat/conf/ssl.crt from tomcat-hostpath1 (rw)
      /usr/local/tomcat/conf/ssl.key from tomcat-hostpath2 (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-8dhnk (ro)

这是我的 docker-compose.yml 文件:


version: '3.6'

networks:
  integration:

services:
  mysql:
    environment:
      MYSQL_USER: 'integrationdb'
      MYSQL_PASSWORD: 'password'
      MYSQL_ROOT_PASSWORD: 'password'
    image: db:poc
    networks:
    - integration
    ports:
    - '3306:3306'
    restart: always
    volumes:
       - ./dbdata:/var/lib/mysql
  tomcat:
    image: adapter:poc
    networks:
    - integration
    ports:
    - '8080:8080'
    - '8443:8443'
    restart: always
    volumes:
      - ./license.json:/run/secrets/rji_license.json
      - ./certificates/ssl.crt:/usr/local/tomcat/conf/ssl.crt
      - ./certificates/ssl.key:/usr/local/tomcat/conf/ssl.key
      - ./server.xml:/usr/local/tomcat/conf/server.xml

工具版本:

kompose: 1.21.0 (992df58d8)

docker: 19.03.9

kubectl:Major:"1", Minor:"18"

我认为我的挑战在于这种类型的卷或文件,我不知道如何将它们迁移或转换为 kubernetes 并使 tomcat pod 运行良好。 有人可以帮我一把吗?

 volumes:
          - ./license.json:/run/secrets/rji_license.json
          - ./certificates/ssl.crt:/usr/local/tomcat/conf/ssl.crt
          - ./certificates/ssl.key:/usr/local/tomcat/conf/ssl.key
          - ./server.xml:/usr/local/tomcat/conf/server.xml

提前致谢。

当 Kompose 警告您时:

WARN Volume mount on the host "/usr/docker/adpater/license.json" isn't supported - ignoring path on the host

这意味着它无法将docker-compose.yml文件的这个片段翻译成 Kubernetes 语法:

volumes:
    - ./license.json:/run/secrets/rji_license.json

在原生 Kubernetes 中,您需要在 ConfigMap 或 Secret 对象中提供此内容,然后将文件挂载到 pod中。 您不能直接访问您从中启动容器的系统上的内容。

您无法在此处直接使用 Kubernetes YAML 文件。 您可以运行kompose convert来生成骨架文件,但是您需要编辑这些文件以添加 ConfigMap、PersistentVolumeClaims(用于数据库存储)以及相关的卷和挂载声明,然后运行kubectl apply -f来实际运行他们。 我会将 Kubernetes YAML 文件检查到源代码管理中,并与您的 Docker Compose 设置并行维护它们。

Move2Kube (它确实支持 docker-compose 翻译)可以处理这种情况并尝试通过与您交互来转换卷。

    ? 6. [] What type of container registry login do you want to use?
Hints:
 [Docker login from config mode, will use the default config from your local machine.]
 No authentication
? 7. Do you want to create PVC for host path [/Users/ashok/wksps/hc/temp/test2/src/dbdata]?:
Hints:
 [Use PVC for persistent storage wherever applicable]
 Yes
? 8. Do you want to create PVC for host path [/Users/ashok/wksps/hc/temp/test2/src/license.json]?:
Hints:
 [Use PVC for persistent storage wherever applicable]
 No
? 9. Do you want to create PVC for host path [/Users/ashok/wksps/hc/temp/test2/src/certificates/ssl.crt]?:
Hints:
 [Use PVC for persistent storage wherever applicable]
 No
? 10. Do you want to create PVC for host path [/Users/ashok/wksps/hc/temp/test2/src/certificates/ssl.key]?:
Hints:
 [Use PVC for persistent storage wherever applicable]
 No
? 11. Do you want to create PVC for host path [/Users/ashok/wksps/hc/temp/test2/src/server.xml]?:
Hints:
 [Use PVC for persistent storage wherever applicable]
 No
? 12. Which storage class to use for persistent volume claim [vol17655897939759777588] used by [mysql]
Hints:
 [If you have a custom cluster, you can use collect to get storage classes from it.]
 default
? 13. Provide the ingress host domain
Hints:
 [Ingress host domain is part of service URL]
 myproject.com
? 14. Provide the TLS secret for ingress
Hints:
 [Enter TLS secret name]

如果做出上述选择,Move2Kube 会创建以下工件:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    move2kube.konveyor.io/service.expose: "true"
  creationTimestamp: null
  labels:
    move2kube.konveyor.io/network/integration: "true"
    move2kube.konveyor.io/service: tomcat
  name: tomcat
spec:
  replicas: 2
  selector:
    matchLabels:
      move2kube.konveyor.io/service: tomcat
  strategy: {}
  template:
    metadata:
      annotations:
        move2kube.konveyor.io/service.expose: "true"
      creationTimestamp: null
      labels:
        move2kube.konveyor.io/network/integration: "true"
        move2kube.konveyor.io/service: tomcat
      name: tomcat
    spec:
      containers:
        - image: adapter:poc
          imagePullPolicy: Always
          name: tomcat
          ports:
            - containerPort: 8080
              protocol: TCP
            - containerPort: 8443
              protocol: TCP
          resources: {}
          volumeMounts:
            - mountPath: /run/secrets/rji_license.json
              name: vol16871681589659214643
            - mountPath: /usr/local/tomcat/conf/ssl.crt
              name: vol12635587774184387470
            - mountPath: /usr/local/tomcat/conf/ssl.key
              name: vol7446232639477381794
            - mountPath: /usr/local/tomcat/conf/server.xml
              name: vol4920239289720818926
      restartPolicy: Always
      volumes:
        - hostPath:
            path: /Users/ashok/wksps/hc/temp/test2/src/license.json
          name: vol16871681589659214643
        - hostPath:
            path: /Users/ashok/wksps/hc/temp/test2/src/certificates/ssl.crt
          name: vol12635587774184387470
        - hostPath:
            path: /Users/ashok/wksps/hc/temp/test2/src/certificates/ssl.key
          name: vol7446232639477381794
        - hostPath:
            path: /Users/ashok/wksps/hc/temp/test2/src/server.xml
          name: vol4920239289720818926
    status: {}

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    move2kube.konveyor.io/service.expose: "true"
  creationTimestamp: null
  labels:
    move2kube.konveyor.io/network/integration: "true"
    move2kube.konveyor.io/service: mysql
  name: mysql
spec:
  replicas: 2
  selector:
    matchLabels:
      move2kube.konveyor.io/service: mysql
  strategy: {}
  template:
    metadata:
      annotations:
        move2kube.konveyor.io/service.expose: "true"
      creationTimestamp: null
      labels:
        move2kube.konveyor.io/network/integration: "true"
        move2kube.konveyor.io/service: mysql
      name: mysql
    spec:
      containers:
        - env:
            - name: MYSQL_USER
              value: integrationdb
            - name: MYSQL_PASSWORD
              value: password
            - name: MYSQL_ROOT_PASSWORD
              value: password
          image: db:poc
          imagePullPolicy: Always
          name: mysql
          ports:
            - containerPort: 3306
              protocol: TCP
          resources: {}
          volumeMounts:
            - mountPath: /var/lib/mysql
              name: vol17655897939759777588
      restartPolicy: Always
      volumes:
        - name: vol17655897939759777588
          persistentVolumeClaim:
            claimName: vol17655897939759777588
status: {}

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  creationTimestamp: null
  name: vol17655897939759777588
spec:
  resources:
    requests:
      storage: 100Mi
  storageClassName: default
  volumeName: vol17655897939759777588
status: {}

基本上取决于您的选择,Move2Kube 将为您创建适当的工件。

您可以在https://konveyor.github.io/move2kube/tutorials/docker-compose/中查看它是如何工作的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM