kubernetes - Kubenetes 访问 api 网络
问题描述
我是 Kub 的新手,我从 docker-compose 转换了我的环境,我有一个包含 python 代码的 pod - 如果我在同一主机上使用我的 docker,我可以访问,但是当它在 pod 上时没有流量进入,
kubectl 配置视图
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://10.10.10.130:6443
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
client-certificate-data: REDACTED
client-key-data: REDACTED
api-service.yaml:
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes hostPath
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: api
name: api
spec:
ports:
- name: "5001"
port: 5001
targetPort: 5001
selector:
io.kompose.service: api
status:
loadBalancer: {}
api-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes hostPath
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: api
name: api
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: api
strategy:
type: Recreate
template:
metadata:
annotations:
kompose.cmd: /snap/kompose/19/kompose-linux-amd64 convert --volumes hostPath
kompose.version: 1.21.0 (992df58d8)
creationTimestamp: null
labels:
io.kompose.service: api
spec:
containers:
- image: 127.0.0.1:5000/api:latest
imagePullPolicy: "Never"
name: api
ports:
- containerPort: 5001
resources: {}
volumeMounts:
- mountPath: /base
name: api-hostpath0
restartPolicy: Always
serviceAccountName: ""
volumes:
- hostPath:
path: /root/ansible/api/base
name: api-hostpath0
status: {}
豆荚日志:
* Serving Flask app 'server' (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on all addresses.
WARNING: This is a development server. Do not use it in a production deployment.
* Running on http://10.244.0.17:5001/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 553-272-086
我尝试达到配置视图显示的内容,我得到了这个: https ://10.10.10.130:6443/
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "forbidden: User \"system:anonymous\" cannot get path \"/\"",
"reason": "Forbidden",
"details": {
},
"code": 403
}
通过容器到达的路径是: https ://10.10.10.130:5001 / 它没有到达容器并说站点不存在 - 这又适用于 docker 容器所以我错过了什么?
谢谢
- 编辑 -
如果我从我进入的主机 curl http://10.244.0.17:5001/(api pod的地址),为什么我不能从外面进入?
还尝试添加 nginx + api pod 部署
template:
spec:
hostNetwork: true
仍然无法到达请帮助
解决方案
找到了解决方案!我需要添加 externalIPs
到我的 pod service.yaml(api 和 nginx)
spec:
ports:
- name: "8443"
port: 8443
targetPort: 80
externalIPs:
- 10.10.10.130
推荐阅读
- javascript - 如何在焦点期间更改值后关注输入的结尾
- java - 如果通过另一个对象访问对象,我应该使用聚合吗?
- r - 替换数据框列中的值
- c# - 如何更新由 webhook 触发的 azure 函数中的记录?
- npm - 无法安装 expo-cli ,抛出错误并花费大量时间
- c# - 是否可以以编程方式生成包含组织结构图的 Excel 文件?
- c++ - dtor 中的这个 unique_lock 是否有任何用途?
- javascript - 使用 Materialize-CSS 和 React 的 TypeError
- arrays - 如何改变这个 foreach 就像 for (i=0;i
我是使用 ejs 的新手,我想将我的数据库数据传递给我的 ejs 文件,但我想将 forEach 语法更改为 for(i=0;i
我找到了一个代码来显示它,但它带来了我所有的数据库数据,我只想从我的数据库中传递 4 个数据
这是我的 server.js 代码
var hotelS
- python - 如何根据字典的值(也可以是列表)动态生成 SQLite 插入查询?