我在家中使用4个RPI设置了一个小的Kubernetes集群。 现在,我要尝试在其中部署一些东西,但是它不起作用。
我已经创建了一个用于测试的Flask小应用程序:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def test():
return {"Hello": "World"}
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0")
它的Dockerfile:
FROM python:3.8-alpine
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
我正在构建它并将其推送到DockerHub中的注册表中。
然后我要设置一个deployment.yaml文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-api
spec:
replicas: 3
selector:
matchLabels:
app: test-api
template:
metadata:
labels:
app: test-api
spec:
containers:
- name: test-api
image: gurkmeja101/pi:latest
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: test-api
spec:
selector:
app: test-api
ports:
- port: 5000
targetPort: 5000
type: NodePort
正在运行kubectl apply -f deployment.yaml
,我得到以下输出:
deployment.apps/test-api created
service/test-api created
PS C:\projects\Python\test> kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 40h
test-api NodePort 10.105.100.68 <none> 5000:31409/TCP 45s
PS C:\projects\Python\test> kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
test-api 0/3 3 0 50s
PS C:\projects\Python\test> kubectl get pods
NAME READY STATUS RESTARTS AGE
test-api-649b447666-97x2r 0/1 CrashLoopBackOff 3 88s
test-api-649b447666-bmmld 0/1 CrashLoopBackOff 3 88s
test-api-649b447666-scnzz 0/1 CrashLoopBackOff 3 88s
描述一个失败的豆荚给我:
Name: test-api-649b447666-97x2r
Namespace: default
Priority: 0
Node: k8s-worker-02/192.168.1.102
Start Time: Wed, 18 Mar 2020 09:05:34 +0100
Labels: app=test-api
pod-template-hash=649b447666
Annotations: <none>
Status: Running
IP: 10.244.2.18
IPs:
IP: 10.244.2.18
Controlled By: ReplicaSet/test-api-649b447666
Containers:
test-api:
Container ID: docker://1418404c27fc5a1a8ef7b557c495a7fbf8f8907ef1dd4d09b4ad5dae02d98b33
Image: gurkmeja101/pi:latest
Image ID: docker-pullable://gurkmeja101/pi@sha256:c2bca364aab8f583c3ed0e64514112475d3e8c77f5dfab979929c5e4b8adb43b
Port: 5000/TCP
Host Port: 0/TCP
State: Waiting
Reason: CrashLoopBackOff
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Wed, 18 Mar 2020 09:07:10 +0100
Finished: Wed, 18 Mar 2020 09:07:10 +0100
Ready: False
Restart Count: 4
Limits:
cpu: 500m
memory: 128Mi
Requests:
cpu: 500m
memory: 128Mi
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-7rmwv (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
default-token-7rmwv:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-7rmwv
Optional: false
QoS Class: Guaranteed
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 119s default-scheduler Successfully assigned default/test-api-649b447666-97x2r to k8s-worker-02
Normal Pulled 24s (x5 over 116s) kubelet, k8s-worker-02 Container image "gurkmeja101/pi:latest" already present on machine
Normal Created 24s (x5 over 116s) kubelet, k8s-worker-02 Created container test-api
Normal Started 23s (x5 over 115s) kubelet, k8s-worker-02 Started container test-api
Warning BackOff 21s (x10 over 112s) kubelet, k8s-worker-02 Back-off restarting failed container
使用docker run -d -p 5000:5000 pi:latest
,我可以毫无问题地运行容器。
对此表示感谢,感谢您的任何帮助!
日志
运行kubectl logs test-api-649b447666-97x2r
会导致:
standard_init_linux.go:211: exec user process caused "exec format error"
答案 0 :(得分:3)
RaspberryPis使用ARM CPU。您的容器映像是针对x86_64构建的。这些不兼容。您需要专门为ARM构建映像。有很多方法可以做到,Docker的官方工具是buildx
。请查看https://www.docker.com/blog/multi-arch-images/以获得其指南,或者如果您要使用其他工具链,请到处搜索。
答案 1 :(得分:0)
由于@coderanger,我成功部署了。
我需要更新Docker,然后确保对Docker构建运行buildx命令。
这是我需要做的,以使其与RPi上的ARM体系结构兼容:docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t gurkmeja101/pi:latest . --push
。