【发布时间】:2020-07-14 08:16:56
【问题描述】:
我有一个非常简单的设置。我正在我的 PC 上使用 Docker Desktop Kubernetes 功能运行 Kubernetes。
- 有 2 个 pod 从 yaml 运行:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
labels:
app: my-nginx
spec:
replicas: 2
selector:
matchLabels:
app: my-nginx
template:
metadata:
labels:
app: my-nginx
spec:
containers:
- name: my-nginx
image: nginx:alpine
-
从命令运行另一个 pod:
kubectl run nginx-standalone --image nginx:alpine -
有一个来自 yaml 的服务:
apiVersion: v1
kind: Service
metadata:
name: nginx-nodeport
spec:
type: NodePort
selector:
app: my-nginx
ports:
- port: 80
targetPort: 80
nodePort: 31000
基本上,由于标签选择器,服务仅“连接”到来自 yaml 部署的 pod。
我在做什么:
- 我“ssh”到 nginx-standalone
- 我安装了 curl(在 nginx-standalone 内部)
- 我尝试了以下方法(在 nginx-standalone 内部):
-
curl nginx-nodeport- 效果很好,我得到了正确的回应 -
curl nginx-nodeport:31000- 不起作用,我得到curl: (7) Failed to connect to nginx-nodeport port 31000: Connection refused
-
我不明白为什么第二个命令没有返回成功的 HTTP 响应。我知道31000 端口可以工作,因为我可以从我的主机PC 上做curl nginx-nodeport:31000。为什么它在 nginx-standalone pod 中不起作用?
【问题讨论】:
-
操作系统?乌本图?红帽?
标签: docker kubernetes