【发布时间】:2021-10-01 13:55:30
【问题描述】:
我在 ubuntu 20.4 的 minikube 中运行 nginx pod 和 Loadbalancer 服务。但是,我无法从浏览器打开 nginx 默认主页。我从输出端点的 Yaml 文件中找不到任何问题。我是否需要做任何其他事情才能从浏览器中访问我的 Nginx pod?
Yaml 文件:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
type: LoadBalancer
ports:
- protocol: TCP
port: 8081
nodePort: 30001
targetPort: 8080
kubectl describe svc nginx-service 输出:
Name: nginx-service
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=nginx
Type: LoadBalancer
IP Family Policy: SingleStack
IP Families: IPv4
IP: 10.105.99.220
IPs: 10.105.99.220
Port: <unset> 8081/TCP
TargetPort: 8080/TCP
NodePort: <unset> 30001/TCP
Endpoints: 172.17.0.3:8080
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
kubectl 描述 svc nginx-service
|-----------|---------------|-------------|---- --------------------------| |命名空间 |姓名 |目标港口 |网址 | |-----------|----------------|-------------|------- ----------------------| |默认 | nginx 服务 | 8081 | http://192.168.99.101:30001 | |-----------|----------------|-------------|------- ----------------------|
卷曲输出
curl http://192.168.99.101:30001
curl: (7) Failed to connect to 192.168.99.101 port 30001: Connection refused
【问题讨论】:
-
可以在部署中将containerPort设置为80
-
谢谢。那行得通。是什么原因?我们是否需要始终在端口 80 上运行 Nginx?
-
nginx 默认监听 80 端口。
标签: ubuntu nginx kubernetes