gpt4 book ai didi

kubernetes - K8:无法使用Nginx反向代理连接Pod

转载 作者:行者123 更新时间:2023-12-02 11:42:16 27 4
gpt4 key购买 nike

我是Kubernetes的新手,我正在尝试在内部计算服务系统中使用Kubernetes托管应用程序。
由于我们的内部计算服务不支持rewrite-target批注,因此我必须使用反向代理来处理重写。
因此,我的流程是:
VIP->服务-> Pod [已重写nginx的Sidecar]-> Pod [应用程序容器]
这是 list :

# Source: reportportal/templates/gateway-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: reportportal-gateway-ingress
labels:
heritage: "Helm"
release: "reportportal"
chart: reportportal-5.2.1
app: "reportportal"
spec:
rules:

- http:
paths:
- path: /
backend:
serviceName: reportportal-ui
servicePort: headless


---
# Source: reportportal/templates/ui-service.yaml
apiVersion: v1
kind: Service
metadata:
name: reportportal-ui
labels:
heritage: "Helm"
release: "reportportal"
chart: reportportal-5.2.1
app: "reportportal"
annotations:
service: ui
infoEndpoint: /info
spec:
ports:
- name: headless
port: 5000
protocol: TCP
targetPort: 5000
selector:
component: reportportal-ui
type: ClusterIP


---
# Source: reportportal/templates/ui-config-map.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: ui-nginx-conf
labels:
sdr.appname: reportportal
data:
nginx.conf: |-
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
keepalive_timeout 65;

upstream ui {
server 127.0.0.1:8080;
}

server {
listen 5000;

location / {
#rewrite /(ui)/?(.*) /$2;
proxy_pass http://ui;
proxy_redirect off;
}
}
}

---
# Source: reportportal/templates/ui-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: reportportal-ui
labels:
heritage: "Helm"
release: "reportportal"
chart: reportportal-5.2.1
app: "reportportal"
spec:
replicas: 1
selector:
matchLabels:
component: reportportal-ui
template:
metadata:
labels:
component: reportportal-ui
annotations:
spec:
containers:
- name: uinginx
image: nginx:alpine
ports:
- containerPort: 5000
protocol: TCP
volumeMounts:
- name: nginx-proxy-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: ui
image: "reportportal/service-ui:5.2.2"
env:
- name: RP_SERVER_PORT
value: "8080"
resources:
requests:
cpu: 100m
memory: 64Mi
limits:
cpu: 200m
memory: 128Mi
readinessProbe:
httpGet:
path: "/health"
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
timeoutSeconds: 3
volumes:
- name: nginx-proxy-config
configMap:
name: ui-nginx-conf

securityContext:
{}
serviceAccountName:
...
我正在使用Minikube(在我的本地计算机上),当我尝试访问URL时,出现“404 not found”页面。
这里的问题是,服务无法连接Pod [Sidecar]!
有人可以帮忙解决此问题吗?
提前致谢!

最佳答案

尝试了此🏂:

# MacOS
minikube start --driver=docker
kubectl apply -f file-with-all-the-manifests.yaml
它对我来说很棒。
从相同 namespace 🏃上的调试 Pane 中:
/ # curl reportportal-ui:5000
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Report Portal</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" href="favicon.ico"><link href="styles.535fa1.css" rel="stylesheet"><link href="main.535fa1.css" rel="stylesheet"></head>
<body>
<div id="app" style="width: 100%; height: 100%"></div>
<div id="popover-root"></div>
<div id="modal-root"></div>
<div id="tooltip-root"></div>
<div id="notification-root"></div>
<div id="screen-lock-root"></div>
<script type="text/javascript" src="polyfills.app.535fa1.js"></script><script type="text/javascript" src="styles.app.535fa1.js"></script><script type="text/javascript" src="main.app.535fa1.js"></script></body>
</html>
/ #
也可以在Nginx边车容器works中使用:
/ # curl 127.0.0.1:8080
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Report Portal</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="shortcut icon" href="favicon.ico"><link href="styles.535fa1.css" rel="stylesheet"><link href="main.535fa1.css" rel="stylesheet"></head>
<body>
<div id="app" style="width: 100%; height: 100%"></div>
<div id="popover-root"></div>
<div id="modal-root"></div>
<div id="tooltip-root"></div>
<div id="notification-root"></div>
<div id="screen-lock-root"></div>
<script type="text/javascript" src="polyfills.app.535fa1.js"></script><script type="text/javascript" src="styles.app.535fa1.js"></script><script type="text/javascript" src="main.app.535fa1.js"></script></body>
</html>
/ #
无论您在哪个环境下运行,都可能需要联网。您的内部计算系统或minikube。查看是否所有 pods 都无法崩溃:
kubectl get pods --all-namespaces
✌️

关于kubernetes - K8:无法使用Nginx反向代理连接Pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63045467/

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