502使用Kubernetes和入口控制器的坏网关
我在Minikube上安装了Kubernetes,配置如下:502使用Kubernetes和入口控制器的坏网关,kubernetes,kubernetes-ingress,Kubernetes,Kubernetes Ingress,我在Minikube上安装了Kubernetes,配置如下: --- apiVersion: apps/v1 kind: Deployment metadata: name: myappdeployment spec: replicas: 5 selector: matchLabels: app: myapp template: metadata: labels: app: myapp spec: con
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: myappdeployment
spec:
replicas: 5
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: custom-docker-image:latest
ports:
- containerPort: 3000
---
kind: Service
apiVersion: v1
metadata:
name: example-service
spec:
selector:
app: myapp
ports:
- protocol: "TCP"
# Port accessible inside cluster
port: 3000
# Port to forward to inside the pod
targetPort: 3000
type: NodePort
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
- http:
paths:
- path: /
backend:
serviceName: example-service
servicePort: 3000
我查看了解决方案,似乎我的配置是。。好吧
当访问我的Minikube地址时,我得到502坏网关有什么错?nginx入口控制器
日志显示:
...
Connection refused while connecting to upstream
...
另一个奇怪的信息是,当我在Kubernetes上设置基本节点服务时,一切正常,当我打开Minikube add时,我会看到一个“Hello world”页面,步骤如下:
我跑
然后我访问了localhost:3000
,看到
This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE
我想原因在日志中更明显,所以我跑了
kubectl logs pods/myappdeployment-5dff57cfb4-6c6bd
得到
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
...
因此,我推断我最初得到的是502,因为没有MySQL设置,所以所有的POD都没有运行。你的应用程序肯定在3000端口上监听吗?如果您使用
kubectl port forward
转发到pod,您是否能够curl
它好吗?啊,有趣的是,我运行了这个程序,似乎在转发3000->3000时出现了一个错误-我查看了单个pod的日志,似乎缺少MySQL设置,这会阻止pod启动,尽管Kubernetes仪表盘是绿色的,谢谢你!学习了一个新的调试技巧,通过端口转发只需一个podNice,很高兴能帮上忙!如果问题解决了,请考虑给出答案。这将更加明确,对社区其他人更有帮助。
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
Waiting for MySQL...
no destination
...