0

我使用Kompose将以下 docker-compose 翻译成 Kubernetes:

---
version: '3'
services:
  freqtrade:
    image: mllamaza/mycoolimg:latest
    restart: unless-stopped
    container_name: mycoolimg
    volumes:
      - "./user_data:/freqtrade/user_data"
    ports:
      - "8080:8080"
    command: >
      start
      --logfile /data/logs/records.log

如果我运行docker-compose up -d它,它工作得很好。但是,当在 Kubernetes 下运行等价物时,pod 无法进行任何外部 HTTP/S 调用并抛出此错误:

urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='mywebsite.com', port=443): Max retries exceeded with url: /my/cool/url/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f95197d2a30>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

此外,该图像还有一个前端网页,可以从http://0.0.0.0:8080.

我使用 Minikube,他们的文档仍然是:

LoadBalancer类型的服务可以通过minikube tunnel 命令公开。它必须在单独的终端窗口中运行以保持 LoadBalancer 运行。

这正是我所做的,该命令没有显示错误:

❯ minikube tunnel           
[sudo] password for mllamaza: 
Status:
        machine: minikube
        pid: 1513359
        route: 10.96.0.0/12 -> 192.168.49.2
        minikube: Running
        services: []
    errors: 
                minikube: no errors
                router: no errors
                load balancer emulator: no errors

但是,如您所见,pod 失败了,因为它无法访问外部 IP(我检查了日志),并且 service/mycoolimg 没有配置外部 IP,如文档中所示:

❯ k get all
NAME                             READY   STATUS             RESTARTS      AGE
pod/mycoolimg-868cdd75bf-krgp6   0/1     CrashLoopBackOff   2 (15s ago)   47s

NAME                 TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE
service/mycoolimg    ClusterIP   10.105.7.210   <none>        8080/TCP   47s
service/kubernetes   ClusterIP   10.96.0.1      <none>        443/TCP    2d13h

NAME                        READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/mycoolimg   0/1     1            0           47s

NAME                                   DESIRED   CURRENT   READY   AGE
replicaset.apps/mycoolimg-868cdd75bf   1         1         0       47s

我错过了什么?这是 Kompose 转换问题和 Minikube 特定配置,还是我错过了一些 Kubernetes 步骤?

这是服务输出:

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose convert --volumes hostPath -o ./deployment
    kompose.version: 1.26.0 (40646f47)
  creationTimestamp: null
  labels:
    io.kompose.service: mycoolimg
  name: mycoolimg
spec:
  ports:
    - name: "8080"
      port: 8080
      targetPort: 8080
  selector:
    io.kompose.service: mycoolimg
status:
  loadBalancer: {}

这是部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose convert --volumes hostPath -o ./deployment
    kompose.version: 1.26.0 (40646f47)
  creationTimestamp: null
  labels:
    io.kompose.service: mycoolimg
  name: mycoolimg
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: mycoolimg
  strategy:
    type: Recreate
  template:
    metadata:
      annotations:
        kompose.cmd: kompose convert --volumes hostPath -o ./deployment
        kompose.version: 1.26.0 (40646f47)
      creationTimestamp: null
      labels:
        io.kompose.service: mycoolimg
    spec:
      containers:
        - args:
            - start
            - --logfile 
            - /data/logs/records.log
          image: mllamaza/mycoolimg:latest
          name: mycoolimg
          ports:
            - containerPort: 8080
          resources: {}
          volumeMounts:
            - mountPath: /data
              name: mycoolimg-hostpath0
      restartPolicy: Always
      volumes:
        - hostPath:
            path: /udata
          name: mycoolimg-hostpath0
status: {}
4

1 回答 1

0

您首先应该查看的是CrashLoopBackOff您的 pod 上的错误,这表明该容器中正在发生的事情正在使您的 pod 崩溃,您可以在此处找到一篇关于如何调试此错误1​​的非常好的文章。

根据提供的信息和代码,问题似乎出在应用程序本身;更准确地说是 Docker 和 Kubernetes 处理入口点和命令的方式,也许入口点作为命令传递给 Kubernetes,反之亦然?

通过复制您的环境但使用不同的映像并取出启动命令成功运行 pod 后得出了该结论:

---
version: '3'
services:
  freqtrade:
    image: expressjs
    restart: unless-stopped
    container_name: mycoolimg
    volumes:
      - "./user_data:/freqtrade/user_data"
    ports:
      - "8080:8080"
#    command: >
#      start
#      --logfile /data/logs/records.log

使用 kompose 通过命令转换为 kubernetes,kompose convert --volumes hostPath我得到以下输出:

WARN Restart policy 'unless-stopped' in service freqtrade is not supported, convert it to 'always' 
INFO Kubernetes file "freqtrade-service.yaml" created 
INFO Kubernetes file "freqtrade-deployment.yaml" created 

使用命令应用部署,kubectl apply -f freqtrade-deployment.yaml我可以看到 pod 正在运行:

NAME                         READY   STATUS    RESTARTS      AGE
freqtrade-86cd7d4469-dkhmw   1/1     Running   0             7s

注意:根据您在 minikube 2中用于推/拉图像的方法,您可能需要imagePullPolicy: Never在容器规范下添加:

    spec:
      containers:
        - image: expressjs
          imagePullPolicy: Never
          name: mycoolimg
          ports:
            - containerPort: 8080
于 2021-12-10T23:36:16.627 回答