我使用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: {}