我目前正在使用Kompose(http://www.kompose.io)将docker-compose配置转换为kubernetes配置文件,从而在kubernetes集群上部署项目。

这是我大学的一个硕士类项目,他们负责kubernetes集群,因此我几乎可以确定它的配置正确。仅供参考,这是该kubernetes集群的版本;

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:23:11Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-13T11:13:49Z", GoVersion:"go1.12.12", Compiler:"gc", Platform:"linux/amd64"}

这是Kompose的版本;
$ kompose version
1.20.0 (f3d54d784)

我的问题如下。我使用命令kompose convert可以正常工作,但是当我尝试使用命令kompose up部署它时,它失败并显示以下错误消息。
FATA Error while deploying application: Get http://localhost:8080/api: dial tcp [::1]:8080: connect: connection refused

这是我第一次使用kubernetes和kompose。我一直在寻找也有此问题的其他人,但对我发现的内容并没有真正帮助。

这是我现在的docker-compose文件:
(我知道我不应该在docker-compose文件中放置密码,但这不是问题的一部分)
version: "3"
services:
  zookeeper-container:
    image: confluentinc/cp-zookeeper
    environment:
      - ZOOKEEPER_CLIENT_PORT=2181
  kafka-container:
    image: confluentinc/cp-kafka
    depends_on:
      - zookeeper-container
    environment:
      - KAFKA_BROKER_ID=1
      - KAFKA_ZOOKEEPER_CONNECT=zookeeper-container:2181
      - KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://kafka-container:9092
      - KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR=1

  route-db:
    image: neo4j:3.5.6
    environment:
      - NEO4J_AUTH=neo4j/route
    ports:
      - 7687:7687
  delay-request-db:
    image: redis

  staff-db:
    image: mongo
  train-db:
    image: mongo

  maintenance-db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_ROOT_PASSWORD=maintenancedatabase
      - MYSQL_DATABASE=Maintenance
  station-db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_ROOT_PASSWORD=stationdatabase
      - MYSQL_DATABASE=Station
  ticket-sale-db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_ROOT_PASSWORD=ticketsaledatabase
      - MYSQL_DATABASE=TicketSale
  ticket-validation-db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_ROOT_PASSWORD=ticketvalidationdatabase
      - MYSQL_DATABASE=TicketValidation
  timetable-db:
    image: mysql:5.7
    command: --default-authentication-plugin=mysql_native_password
    environment:
      - MYSQL_ROOT_PASSWORD=timetabledatabase
      - MYSQL_DATABASE=Timetable

  delay-service:
    build: ./railway-app-delay
    image: gilliswerrebrouck/railway-app-delay-service
    volumes:
      - ./railway-app-delay/target:/app
    links:
      - kafka-container
      - zookeeper-container
    depends_on:
      - kafka-container
      - zookeeper-container
  maintenance-service:
    build: ./railway-app-maintenance
    image: gilliswerrebrouck/railway-app-maintenance-service
    volumes:
      - ./railway-app-maintenance/target:/app
    links:
      - kafka-container
      - zookeeper-container
      - maintenance-db
    depends_on:
      - kafka-container
      - zookeeper-container
      - maintenance-db
  route-service:
    build: ./railway-app-route-management
    image: gilliswerrebrouck/railway-app-route-management-service
    volumes:
      - ./railway-app-route-management/target:/app
    links:
      - kafka-container
      - zookeeper-container
      - route-db
    depends_on:
      - kafka-container
      - zookeeper-container
      - route-db
  staff-service:
    build: ./railway-app-staff
    image: gilliswerrebrouck/railway-app-staff-service
    volumes:
      - ./railway-app-staff/target:/app
    links:
      - kafka-container
      - zookeeper-container
      - staff-db
    depends_on:
      - kafka-container
      - zookeeper-container
      - staff-db
  station-service:
    build: ./railway-app-station
    image: gilliswerrebrouck/railway-app-station-service
    volumes:
      - ./railway-app-station/target:/app
    links:
      - kafka-container
      - zookeeper-container
      - station-db
      - delay-request-db
    depends_on:
      - kafka-container
      - zookeeper-container
      - station-db
      - delay-request-db
  ticket-sale-service:
    build: ./railway-app-ticket-sale
    image: gilliswerrebrouck/railway-app-ticket-sale-service
    volumes:
      - ./railway-app-ticket-sale/target:/app
    links:
      - kafka-container
      - zookeeper-container
      - ticket-sale-db
    depends_on:
      - kafka-container
      - zookeeper-container
      - ticket-sale-db
  ticket-validation-service:
    build: ./railway-app-ticket-validation
    image: gilliswerrebrouck/railway-app-ticket-validation-service
    volumes:
      - ./railway-app-ticket-validation/target:/app
    links:
      - kafka-container
      - zookeeper-container
      - ticket-validation-db
    depends_on:
      - kafka-container
      - zookeeper-container
      - ticket-validation-db
  timetable-service:
    build: ./railway-app-timetable
    image: gilliswerrebrouck/railway-app-timetable-service
    volumes:
      - ./railway-app-timetable/target:/app
    links:
      - kafka-container
      - zookeeper-container
      - timetable-db
      - route-service
      - station-service
      - train-service
    depends_on:
      - kafka-container
      - zookeeper-container
      - timetable-db
      - route-service
      - station-service
      - train-service
  train-service:
    build: ./railway-app-train
    image: gilliswerrebrouck/railway-app-train-service
    volumes:
      - ./railway-app-train/target:/app
    links:
      - kafka-container
      - zookeeper-container
      - train-db
    depends_on:
      - kafka-container
      - zookeeper-container
      - train-db
  apigateway:
    build: ./railway-app-api-gateway
    image: gilliswerrebrouck/railway-app-api-gateway-service
    volumes:
      - ./railway-app-api-gateway/target:/app
    links:
      - kafka-container
      - zookeeper-container
      - delay-service
      - maintenance-service
      - route-service
      - staff-service
      - station-service
      - ticket-sale-service
      - ticket-validation-service
      - timetable-service
      - train-service
    depends_on:
      - kafka-container
      - zookeeper-container
      - delay-service
      - maintenance-service
      - route-service
      - staff-service
      - station-service
      - ticket-sale-service
      - ticket-validation-service
      - timetable-service
      - train-service
    ports:
      - 8080:8080

  frontend:
    build: ./railway-app-frontend
    image: gilliswerrebrouck/railway-app-frontend
    volumes:
      - ./railway-app-frontend/target:/app
    links:
      - apigateway
      - route-db
    depends_on:
      - apigateway
      - route-db
    ports:
      - 80:80

任何人都有关于如何解决此问题或如何解决此问题的提示?

更新:

这些是kompose convert命令生成的文件

docker - 无法使用Kompose部署到Kubernetes集群-LMLPHP

最佳答案

我已经解决了此问题,方法是将部署文件中的所有apiversions从v1beta2替换为apps / v1,并为每个部署添加了选择器。

selector:
    matchLabels:
      app: ...

然后,我没有使用Kompose up命令进行部署,因为这给了我一个错误,但是我使用了kubectl create -f <file(s)>命令进行部署,并且成功完成了而没有连接错误。仍然有一些 pod 崩溃,但我认为这与原始问题无关。

关于docker - 无法使用Kompose部署到Kubernetes集群,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59690266/

10-12 00:25