我正在尝试在Kubernetes上设置一个简单的HTTP Web服务器,并使用临时外部IP公开它。但是,当尝试访问x.x.x.x /something
时,我得到:
Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds.
我的配置很简单:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 1
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: gcr.io/my-repo-name
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /healthz
port: 8080
readinessProbe:
initialDelaySeconds: 10
httpGet:
path: /healthz
port: 8080
---
apiVersion: v1
kind: Service
metadata:
name: web-balancer-service
spec:
selector:
app: web
type: NodePort
ports:
- protocol: TCP
port: 8080
targetPort: 32111
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-ingress-app
spec:
backend:
serviceName: web-balancer-service
servicePort: 8080
如果我describe ingress
,我会看到后端是“Unknown”。 我的spec
有问题吗?
Name: my-ingress-app
Namespace: default
Address: x.x.x.x
Default backend: web-balancer-service:8080 (10.60.0.57:32111)
Rules:
Host Path Backends
---- ---- --------
* * web-balancer-service:8080 (10.60.0.57:32111)
Annotations:
ingress.kubernetes.io/backends: {"k8s-be-30330--f4bbd8cbe40f4567":"Unknown"}
ingress.kubernetes.io/forwarding-rule: k8s-fw-default-my-ingress-app--f4bbd8cbe40f4567
ingress.kubernetes.io/target-proxy: k8s-tp-default-my-ingress-app--f4bbd8cbe40f4567
ingress.kubernetes.io/url-map: k8s-um-default-my-ingress-app--f4bbd8cbe40f4567
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal ADD 7m18s loadbalancer-controller default/my-ingress-app
Normal CREATE 6m12s loadbalancer-controller ip: x.x.x.x
首先,确保容器(deplpyments的pod)已经监听了
32111
端口。其作为服务上的targetPort,这意味着服务将在端口8080上接收流量,但将其发送到端口32111上。像:-(流量)--->:8080(service)--->:32111(pods)
我怀疑这是因为你的
Pod sepc
中您有containerPort: 8080
,这表明Pod实际上也监听8080
,而不是32111
。你要把Service的targetPort也更改为8080。
谢谢您!!,问题确实是 targetPort
你的答案