简体   繁体   English

如何在kubernetes上运行docker-compose.yaml?

[英]how to run docker-compose.yaml on kubernetes?

My docker-compose file consisting of tomcat7 server and mysql database 我的docker-compose文件由tomcat7服务器和mysql数据库组成


version: '3'
services:
      mysql:
        image: suji165475/vignesh:latest
        ports:
          - "3066:3066"

      tomcat:
        image: suji165475/vignesh:tomcatserver
        container_name: tomcat7hope
        ports:
          - "8080:8080"

I built the images using docker files 我使用docker文件构建了图像

FROM mysql
ENV MYSQL_ROOT_PASSWORD=root
ADD init.sql /docker-entrypoint-initdb.d
FROM picoded/tomcat7
COPY data-core-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/data-core-0.0.1-SNAPSHOT.war

how to run this on kubernetes clusture?? 如何在kubernetes集群上运行它? I already tried kompose convert and my war file wont start in tomcats application manager.But the war file starts succesfully using docker-compose up. 我已经尝试过kompose convert并且war文件不会在tomcats应用程序管理器中启动。但是war文件使用docker-compose up成功启动了。

Why am I facing this issue only in kubernetes and not when directly running docker-compose up.Please help me by letting me know what changes I should make to the kubernetes yaml files. 为什么我只能在kubernetes中而不是直接运行docker-compose up时才遇到此问题。请让我知道我应该对kubernetes yaml文件进行哪些更改来帮助我。

mysql-deployment.yaml mysql-deployment.yaml

 apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.18.0 (06a2e56)
  creationTimestamp: null
  labels:
    io.kompose.service: mysql
  name: mysql
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: mysql
    spec:
      containers:
      - image: suji165475/vignesh:latest
        name: mysql
        ports:
        - containerPort: 3066
        resources: {}
      restartPolicy: Always
status: {}

tomcat-deployment.yaml tomcat-deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.18.0 (06a2e56)
  creationTimestamp: null
  labels:
    io.kompose.service: tomcat
  name: tomcat
spec:
  replicas: 1
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: tomcat
    spec:
      containers:
      - image: suji165475/vignesh:tomcatserver
        name: tomcat7hope
        ports:
        - containerPort: 8080
        resources: {}
      restartPolicy: Always
status: {}

mysql-service.yaml mysql-service.yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.18.0 (06a2e56)
  creationTimestamp: null
  labels:
    io.kompose.service: mysql
  name: mysql
spec:
  ports:
  - name: "3066"
    port: 3066
    targetPort: 3066
  selector:
    io.kompose.service: mysql
status:
  loadBalancer: {}

tomcat-service.yaml tomcat-service.yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert
    kompose.version: 1.18.0 (06a2e56)
  creationTimestamp: null
  labels:
    io.kompose.service: tomcat
  name: tomcat
spec:
  ports:
  - name: "8080"
    port: 8080
    targetPort: 8080
  selector:
    io.kompose.service: tomcat
status:
  loadBalancer: {}

Let me make it clear, you can't "run docker-compose" on Kubernetes. 让我说清楚,您不能在Kubernetes上“运行docker-compose”。 If you wanted to do that, you should not be using Kubernetes. 如果您想这样做,则不应该使用Kubernetes。

With that said, using kompose is not such a great idea. 话虽如此,使用kompose并不是一个好主意。 Docker compose yaml files are all different and kompose simply makes a guess as to what the associated Kubernetes manifests would look like. Docker kompose文件各不相同,而kompose只是猜测关联的Kubernetes清单是什么样子。 If your application is very simple and you are lucky, kompose might give you your manifests ready to be deployed, but that is not usually the case. 如果您的应用程序非常简单并且很幸运, kompose可能会为您准备好要部署的清单,但是通常情况并非如此。

There could be a few reasons why this is not working for you: 某些原因可能对您不起作用:

  • your tomcat application is not correctly referencing your mysql service 您的tomcat应用程序未正确引用您的mysql服务
  • your mysql deployment is missing some variables or mounted volumes/files 您的mysql部署缺少一些变量或装入的卷/文件

Your tomcat app can refer to your mysql db through mysql:3066 and you might need to add some environment variables in your tomcat deployment such as db name, db username and db password for authentication. 您的tomcat应用程序可以通过mysql:3066引用您的mysql数据库,并且您可能需要在tomcat部署中添加一些环境变量,例如用于身份验证的数据库名称,数据库用户名和数据库密码。 Here are your edited tomcat manifests: 这是您编辑的tomcat清单:

deployment.yaml deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: tomcat
  namespace: default
  labels:
    app: tomcat
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tomcat
  template:
    metadata:
      labels:
        app: tomcat
    spec:
      containers:
      - image: suji165475/vignesh:tomcatserver
        name: tomcat7hope
        ports:
        - containerPort: 8080

service.yaml service.yaml

apiVersion: v1
kind: Service
metadata:
  name: tomcat
  namespace: default
  labels:
    app: tomcat
spec:
  ports:
  - name: "8080"
    port: 8080
    targetPort: 8080
  selector:
    app: tomcat

Your mysql deployment might require a PersistentVolumeClaim or emptyDir in order to keep your data. 您的mysql部署可能需要PersistentVolumeClaimemptyDir才能保留数据。 Take a look at attached volumes and confirm that you are not missing any volume mounts or environment variables that are needed. 查看附加的卷,并确认您没有丢失任何需要的卷安装或环境变量。 Here are your edited mysql manifests: 这是您编辑的mysql清单:

deployment.yaml deployment.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: mysql
  namespace: default
  labels:
    app: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: suji165475/vignesh:latest
        name: mysql
        ports:
        - containerPort: 3066
        env:
        - name: MYSQL_ROOT_PASSWORD
          value: root

service.yaml service.yaml

apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: default
  labels:
    app: mysql
spec:
  ports:
  - name: "3066"
    port: 3066
    targetPort: 3066
  selector:
    app: mysql

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

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