kubectl端口转发会忽略loadBalance服务吗? [英] Does kubectl port-forward ignore loadBalance services?
问题描述
我的环境:具有最新Minikube/Docker的Mac开发机
My Environment: Mac dev machine with latest Minikube/Docker
我使用一个简单的Django REST API"hello world"构建了一个本地的docker镜像.我正在运行一个包含3个副本的部署.这是我的yaml
文件,用于对其进行定义:
I built (locally) a simple docker image with a simple Django REST API "hello world".I'm running a deployment with 3 replicas. This is my yaml
file for defining it:
apiVersion: v1
kind: Service
metadata:
name: myproj-app-service
labels:
app: myproj-be
spec:
type: LoadBalancer
ports:
- port: 8000
selector:
app: myproj-be
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: myproj-app-deployment
labels:
app: myproj-be
spec:
replicas: 3
selector:
matchLabels:
app: myproj-be
template:
metadata:
labels:
app: myproj-be
spec:
containers:
- name: myproj-app-server
image: myproj-app-server:4
ports:
- containerPort: 8000
env:
- name: DATABASE_URL
value: postgres://myname:@10.0.2.2:5432/myproj2
- name: REDIS_URL
value: redis://10.0.2.2:6379/1
当我应用此yaml
时,它会正确生成东西.
-一次部署
-一项服务
-三个豆荚
When I apply this yaml
it generates things correctly.
- one deployment
- one service
- three pods
部署:
NAME READY UP-TO-DATE AVAILABLE AGE
myproj-app-deployment 3/3 3 3 79m
服务:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 83m
myproj-app-service LoadBalancer 10.96.91.44 <pending> 8000:31559/TCP 79m
豆荚:
NAME READY STATUS RESTARTS AGE
myproj-app-deployment-77664b5557-97wkx 1/1 Running 0 48m
myproj-app-deployment-77664b5557-ks7kf 1/1 Running 0 49m
myproj-app-deployment-77664b5557-v9889 1/1 Running 0 49m
有趣的是,当我SSH
进入Minikube
并使用curl 10.96.91.44:8000
命中服务时,它尊重服务的LoadBalancer
类型,并在我命中端点时间和时间时在所有三个Pod之间旋转再次.我可以在返回的结果中看到这一点,我确保已将Pod的HOSTNAME包括在内.
The interesting thing is that when I SSH
into the Minikube
, and hit the service using curl 10.96.91.44:8000
it respects the LoadBalancer
type of the service and rotates between all three pods as I hit the endpoints time and again. I can see that in the returned results which I have made sure to include the HOSTNAME of the pod.
但是,当我尝试使用kubectl port-forward service/myproj-app-service 8000:8000
从Hosting Mac访问服务时,每次碰到端点时,都会得到相同的Pod进行响应.它没有负载平衡.我可以很清楚地看到,当我kubectl logs -f <pod>
到所有三个Pod时,只有其中一个正在处理命中,而另外两个则处于闲置状态...
However, when I try to access the service from my Hosting Mac -- using kubectl port-forward service/myproj-app-service 8000:8000
-- Every time I hit the endpoint, I get the same pod to respond. It doesn't load balance. I can see that clearly when I kubectl logs -f <pod>
to all three pods and only one of them is handling the hits, as the other two are idle...
这是kubectl port-forward
限制还是问题?还是我在这里错过了更大的东西?
Is this a kubectl port-forward
limitation or issue? or am I missing something greater here?
推荐答案
原因是由于容器中留有Python * .pyc文件,导致我的pod随机处于崩溃状态.当Django在多容器Kubernetes部署中运行时,这会导致问题.一旦我删除了此问题,并且所有pod都成功运行,轮询便开始工作了.
The reason was that my pods were randomly in a crashing state due to Python *.pyc files that were left in the container. This causes issues when Django is running in a multi-pod Kubernetes deployment. Once I removed this issue and all pods ran successfully, the round-robin started working.
这篇关于kubectl端口转发会忽略loadBalance服务吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!