docker - Kubernetes,无法使用外部 IP 地址访问 Pod
问题描述
我是 Kubernetes 新手,遇到了一些问题。
我有一个 ubuntu 服务器,我正在处理它。我创建了 pod 和服务,还有一个 API-Gateway pod 和服务。我想用我的电脑上的 ubuntu 服务器 IP 地址访问这个 pod。
但我无法从服务器外部访问此 pod。我在 docker 映像上的应用程序在 80 端口上运行。
我的 api-gateway.yaml 文件是这样的:
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-gateway
spec:
replicas: 1
selector:
matchLabels:
app: api-gateway
template:
metadata:
labels:
app: api-gateway
spec:
containers:
- name: api-gateway
image: myapi/api-gateway
---
apiVersion: v1
kind: Service
metadata:
name: api-gateway
spec:
selector:
app: api-gateway
ports:
- name: api-gateway
protocol: TCP
port: 80
targetPort: 80
nodePort: 30007
type: NodePort
externalIPs:
- <My Ubuntu Server IP Adress>
当我输入kubectl get services api-gateway时,我得到
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
api-gateway NodePort 10.104.42.32 <MyUbuntuS IP> 80:30007/TCP 131m
当我输入kubectl describe services api-gateway时,我得到
Name: api-gateway
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=api-gateway
Type: NodePort
IP Families: <none>
IP: 10.104.42.32
IPs: 10.104.42.32
External IPs: <My Ubuntu Server IP Adress>
Port: api-gateway 80/TCP
TargetPort: 80/TCP
NodePort: api-gateway 30007/TCP
Endpoints: 172.17.0.4:80
Session Affinity: None
External Traffic Policy: Cluster
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Type 30m service-controller ClusterIP -> LoadBalancer
Normal Type 6m10s service-controller NodePort -> LoadBalancer
Normal Type 77s (x2 over 9m59s) service-controller LoadBalancer -> NodePort
那么,如何在我的 PC 浏览器或 Postman 上访问此 pod?
解决方案
推荐阅读
- python - 用python绘制多数据框图
- node.js - 导出声明类型 ResourceType = 小写
, 使用 Puppeteer 和 typescript 构建 nodejs 应用程序时出错 - python - pandas 检查子集中的条件以获取值
- javascript - 如何使用 Google Drive api V3 将图像下载到浏览器客户端?
- graphql - 在 Nestjs 中使用 graphql 进行授权
- php - kylekatarnls/update-helper 安装失败
- python - 在指定位置创建均值 = 1 的高斯二维数组
- azure-devops - Azure DevOps AAD 选项卡将不存在的用户显示为已断开连接
- node.js - Postgres NodeJS 批量更新插入超时
- javascript - 用数据 ASP.NET CORE MVC Jquery 填充弹出模式