gpt4 book ai didi

amazon-web-services - AWS EKS,如何直接从浏览器访问 Pod?

转载 作者:行者123 更新时间:2023-12-02 20:41:29 24 4
gpt4 key购买 nike

我是 kubernetes 的新手。上周我学习了节点、Pod、集群、服务和部署。

有了这个,我试图更深入地了解 kubernetes 的网络是如何工作的。我只想公开一个简单的 nginx docker 网页并从我的浏览器中点击它。

我们的 VPC 设置为直接连接,因此我可以访问 EC2 实例的私有(private) IP 地址。我还暂时使用 aws 上的 UI 将 EKS 集群设置为 private。出于测试目的,我添加了我的 cidr 范围以允许在所有 TCP 上作为 EKS 集群 UI 中的附加安全组。

这是我的基本服务和部署定义:

apiVersion: v1
kind: Service
metadata:
name: testing-nodeport
namespace: default
labels:
infrastructure: fargate
app: testing-app
spec:
type: NodePort
selector:
app: testing-app
ports:
- port: 80
targetPort: testing-port
protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: testing-deployment
namespace: default
labels:
infrastructure: fargate
app: testing-app
spec:
replicas: 1
selector:
matchLabels:
infrastructure: fargate
app: testing-app
template:
metadata:
labels:
infrastructure: fargate
app: testing-app
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- name: testing-port
containerPort: 80

当我运行时,我可以看到一切都在正常运行:

kubectl get all -n default

但是,当我尝试访问 80 端口上的 NodePort IP 地址时,我无法从浏览器加载它。

如果我首先在以下 url 设置一个 kubectl 代理,我就可以访问 pod(因为代理在端口 8001 上启动):

http://localhost:8001/api/v1/namespaces/default/services/testing-nodeport:80/proxy/

此时我几乎迷路了。我不知道自己做错了什么,也不知道为什么我无法在 kubectl proxy 命令之外访问基本的 nginx docker。

最佳答案

如果使用 proxy 选项会怎样?像这样:

kubectl port-forward -n default service/testing-nodeport 3000:80
Forwarding from 127.0.0.1:3000 -> 80
Forwarding from [::1]:3000 -> 80

在此之后,您可以从 localhost:3000 访问您的 K8S 服务。更多信息 here

关于amazon-web-services - AWS EKS,如何直接从浏览器访问 Pod?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63162773/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com