[英]Ubuntu: Cannot access Kubernetes service from outside cluster
我是 K8s 的新手,我在尝试从集群外部连接到 K8s NodePort 服务时遇到了问题。
当我尝试使用以下 URL 从本地计算机访问它时,我无法加载 nginx 默认页面:http://localhost:31008
我知道这是一个常见问题,我参考了以下解决方案,
无法访问 Kubernetes 集群外的 NodePort 服务
无法使用 NodePort 服务从浏览器访问 Microk8s 服务
然而,他们都没有为我工作。
任何有关此问题的指导将不胜感激。 谢谢你。
设置:
服务器操作系统:AWS 上的 Ubuntu 服务器
K8s:minikube
下面是我的部署 YAML:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: front-end
name: nginx
template:
metadata:
name: nginx
labels:
app: front-end
name: nginx
spec:
containers:
- name: nginx
image: nginx
以下是我的服务 YAML:
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: front-end
name: nginx
ports:
- port: 8080
targetPort: 8080
nodePort: 31008
下面是kubectl get all
命令的输出,
由于Nginx在默认端口80上运行,因此目标端口配置中存在问题
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort
selector:
app: front-end
name: nginx
ports:
- port: 8080
targetPort: 80
nodePort: 31008
目标端口应该是80
Nginx 的配置:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
selector:
matchLabels:
run: my-nginx
replicas: 2
template:
metadata:
labels:
run: my-nginx
spec:
containers:
- name: my-nginx
image: nginx
ports:
- containerPort: 80
参考文档: https : //kubernetes.io/docs/concepts/services-networking/connect-applications-service/
对于使用 docker + minikube 并面临上述问题的人,这里提供了解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.