【发布时间】:2020-11-17 07:17:36
【问题描述】:
我正在使用 k3d(docker 中的 k3s)做一些教程,我的 yml 看起来像这样:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
labels:
app: nginx
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
labels:
app: nginx
spec:
type: NodePort
selector:
app: nginx
ports:
- name: http
port: 80
targetPort: 80
生成的节点端口为 31747:
:~$ kubectl get service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.43.0.1 <none> 443/TCP 18m
nginx NodePort 10.43.254.138 <none> 80:31747/TCP 17m
:~$ kubectl get endpoints
NAME ENDPOINTS AGE
kubernetes 172.18.0.2:6443 22m
nginx 10.42.0.8:80 21m
但是 wget 不起作用:
:~$ wget localhost:31747
Connecting to localhost:31747 ([::1]:31747)
wget: can't connect to remote host: Connection refused
:~$
我错过了什么?我确保我的标签都写着app: nginx,而我的containerPort、port 和targetPort 都是80
【问题讨论】:
-
是否有可能使用
localhost打这个?集群是否在 Docker 网络host上运行?请说清楚。您也可以尝试kubectl port-forward pod/<podname> 8080:80和curl localhost:8080来验证 Pod IP 是否正常。 -
是的,当我运行
kubectl port-forward pod/<podname> 8080:80wget 工作时。
标签: nginx kubernetes k3s