1

我目前正在通过使用 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命令生成的文件

在此处输入图像描述

4

1 回答 1

2

I've solved it by replacing all apiversions in the deployment files from v1beta2 to apps/v1 and by adding a selector to each deployment.

selector:
    matchLabels:
      app: ...

I then didn't use the command Kompose up to deploy since this gives me an error, but I used the command kubectl create -f <file(s)> to deploy and this succeeded without the connection error. There are still some pods crashing but I don't think it has anything to do with this original problem.

于 2020-01-11T12:17:09.983 回答