AWS-EKS 部署的 pod 以类型服务公开节点端口无法通过节点端口 IP 和公开端口访问
AWS-EKS deployed pod is exposed with type service Node Port is not accessible over nodePort IP and exposed port
我已经使用 EKS 和 Terraform 在 AWS 上创建了 k8s 集群,遵循此文档 https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html。
我有一个工作节点。Note: Everything is in Private Subnets
只是 运行 node.js hello-world 容器
pod 定义代码
kind: Pod
metadata:
name: nodehelloworld.example.com
labels:
app: helloworld
spec:
containers:
- name: k8s-demo
image: wardviaene/k8s-demo
ports:
- name: nodejs-port
containerPort: 3000
服务定义代码
apiVersion: v1
kind: Service
metadata:
name: helloworld-service
spec:
ports:
- port: 31001
nodePort: 31001
targetPort: nodejs-port
protocol: TCP
selector:
app: helloworld
type: NodePort
kubectl get pods
显示我的 pod 已启动并且 运行
nodehelloworld.example.com 1/1 Running 0 17h
kubectl get svc
说明我的服务也创建好了
helloworld-service NodePort 172.20.146.235 <none> 31001:31001/TCP 16h
kubectl describe svc helloworld-service
它有正确的 end-point 和正确的 selector
所以问题来了
当我点击 NodeIP:exposed 端口(即 31001)时,我得到 This site can’t be reached
然后我用了kubeclt port-forward podname 3000:3000
我可以打 curl -v localhost:3000
可以到达
我检查了我的安全组入站规则是来自我的 CIDR 块的 0-65535。
我还有什么遗漏的吗?
如果您尝试从集群外部连接,那么在工作节点的安全组中,您将必须添加自定义 TCP 条目以启用端口 31001 上的入站流量。
如果这不起作用,请确保您能够通过该 IP 连接到节点。我通常使用 VPN 客户端连接。
已修复..
在 AWS EKS 上,节点端口不像在 Pure Kubernetes 上那样工作。
当你暴露
- port: 31001
targetPort: nodejs-port
protocol: TCP
31001 这是 clusterIP 端口将被暴露。
为了获得 nodePort,您必须描述您的服务并查找 NodePort 是公开的描述
我已经使用 EKS 和 Terraform 在 AWS 上创建了 k8s 集群,遵循此文档 https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html。
我有一个工作节点。Note: Everything is in Private Subnets
只是 运行 node.js hello-world 容器
pod 定义代码
kind: Pod
metadata:
name: nodehelloworld.example.com
labels:
app: helloworld
spec:
containers:
- name: k8s-demo
image: wardviaene/k8s-demo
ports:
- name: nodejs-port
containerPort: 3000
服务定义代码
apiVersion: v1
kind: Service
metadata:
name: helloworld-service
spec:
ports:
- port: 31001
nodePort: 31001
targetPort: nodejs-port
protocol: TCP
selector:
app: helloworld
type: NodePort
kubectl get pods
显示我的 pod 已启动并且 运行
nodehelloworld.example.com 1/1 Running 0 17h
kubectl get svc
说明我的服务也创建好了
helloworld-service NodePort 172.20.146.235 <none> 31001:31001/TCP 16h
kubectl describe svc helloworld-service
它有正确的 end-point 和正确的 selector
所以问题来了
当我点击 NodeIP:exposed 端口(即 31001)时,我得到 This site can’t be reached
然后我用了kubeclt port-forward podname 3000:3000
我可以打 curl -v localhost:3000
可以到达
我检查了我的安全组入站规则是来自我的 CIDR 块的 0-65535。
我还有什么遗漏的吗?
如果您尝试从集群外部连接,那么在工作节点的安全组中,您将必须添加自定义 TCP 条目以启用端口 31001 上的入站流量。
如果这不起作用,请确保您能够通过该 IP 连接到节点。我通常使用 VPN 客户端连接。
已修复.. 在 AWS EKS 上,节点端口不像在 Pure Kubernetes 上那样工作。 当你暴露
- port: 31001
targetPort: nodejs-port
protocol: TCP
31001 这是 clusterIP 端口将被暴露。
为了获得 nodePort,您必须描述您的服务并查找 NodePort 是公开的描述