创建了 svc 无法访问

2021-05-04 15:52:30 +08:00
 root01
test-nginx.yaml
```
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-nginx
spec:
replicas: 2
selector:
matchLabels:
app: test-nginx
template:
metadata:
labels:
app: test-nginx
spec:
containers:
- name: web
image: nginx:1.8
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
```
test-nginx-svc.yaml
```
apiVersion: v1
kind: Service
metadata:
name: test-nginx
labels:
app: tets-nginx
spec:
selector:
app: test-nginx
type: NodePort
ports:
- port: 80
protocol: TCP
name: web
targetPort: http
nodePort: 31180


```
netstat -ntlp |grep 31180
tcp 0 0 0.0.0.0:31180 0.0.0.0:* LISTEN 4057/kube-proxy

### 显示已经成功了 ,pod 也是 running 状态
### 访问节点:192.168.145.146:31180 (wget/curl 都无法访问)
### 之前已经部署了 kubesphere,也是可以访问的,端口不冲突,请问该怎么排查?
# kubectl get pod -l app=test-nginx
NAME READY STATUS RESTARTS AGE
test-nginx-55546c8c-42r5n 1/1 Running 0 13m
test-nginx-55546c8c-5gqk5 1/1 Running 0 13m
1342 次点击
所在节点    Kubernetes
7 条回复
root01
2021-05-04 16:12:42 +08:00
已经修正两个 YAML 文件中的 labels=test-nginx
root01
2021-05-04 16:14:22 +08:00
但是仍无法访问
SignLeung
2021-05-04 17:21:37 +08:00
可以 curl podIP:containerPort 看看能不能访问
root01
2021-05-04 17:36:59 +08:00
@SignLeung
# nslookup shun-nginx
Server: 10.96.0.10
Address 1: 10.96.0.10 kube-dns.kube-system.svc.cluster.local

Name: shun-nginx
Address 1: 10.104.210.29 shun-nginx.default.svc.cluster.local
/ # wget shun-nginx
Connecting to shun-nginx (10.104.210.29:80)
wget: can't connect to remote host (10.104.210.29): Connection refused
root01
2021-05-04 17:37:44 +08:00
@SignLeung busybox 没 curl emmm
freezex
2021-05-04 18:05:07 +08:00
svc 里的这个: targetPort: http
deploy 里没有
root01
2021-05-04 20:06:29 +08:00
@freezex 解决了,targetPort 设置为 80 端口就可以了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/774862

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX