0

我正在尝试创建以下内容:

  1. Deployment对于蒙戈
  2. Deployment对于 mongo-express
  3. ClusterIp对于蒙戈
  4. ClusterIp对于 mongo-express
  5. 将请求路由到 mongo-express 的入口服务

我希望能够去xyz.com/admin/auth-db-gui看看 mongo-express gui。

我在 Linux minikube 上运行它。

去时xyz.com/admin/auth-db-gui,我得到 503 Service Temporarily Unavailable,但是在执行时kubectl get pods,我可以看到 2 个 Pod 正在运行。

我将手动设置映射,xyz.com因为/etc/hosts这仅用于开发目的

数据库.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-db-deployment
spec:
  selector:
    matchLabels:
      app: auth-db
  template:
    metadata:
      labels:
        app: auth-db
    spec:
      containers:
        - name: auth-db
          image: mongo
---
apiVersion: v1
kind: Service
metadata:
  name: auth-db-service
spec:
  selector:
    app: auth-db
  ports:
    - name: auth-db
      protocol: TCP
      port: 27017
      targetPort: 27017

数据库-gui

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-db-gui-deployment
spec:
  selector:
    matchLabels:
      app: auth-db-gui
  template:
    metadata:
      labels:
        app: auth-db-gui
    spec:
      containers:
        - name: auth-db-gui
          image: mongo-express
          env:
            - name: ME_CONFIG_MONGODB_SERVER
              value: auth-db-service
---
apiVersion: v1
kind: Service
metadata:
  name: auth-db-gui-service
spec:
  selector:
    app: auth-db-gui
  ports:
    - name: auth-db-gui
      protocol: TCP
      port: 27017
      targetPort: 27017

入口.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: xyz-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
    - host: xyz.com
      http:
        paths:
          - path: /admin/auth-db-gui
            backend:
              serviceName: auth-db-gui-service
              servicePort: 8081

对不起,如果上面有明显的错误。

4

1 回答 1

1

我注意到在某些情况下503 表示端口配置正确。

我已经测试了您的入口,以及服务和部署,并且在纠正入口对象中的端口错误后,它工作得很好:

curl -H "Host:  xyz.com"  "192.168.49.2/admin/auth-db-gui"   
{
  "path": "/admin/auth-db-gui",
  "headers": {
    "host": "xyz.com",
    "x-request-id": "ff272df6d729af6c1fb4d5f510de88f4",
    "x-real-ip": "192.168.49.1",
    "x-forwarded-for": "192.168.49.1",
    "x-forwarded-host": "xyz.com",
    "x-forwarded-port": "80",
    "x-forwarded-proto": "http",
    "x-scheme": "http",
    "user-agent": "curl/7.52.1",
    "accept": "*/*"
  },
  "method": "GET",
  "body": "",
  "fresh": false,
  "hostname": "xyz.com",
  "ip": "192.168.49.1",
  "os": {
    "hostname": "auth-db-gui-deployment-555c77cf75-fjbf2"

出于测试目的,我强烈推荐mendhak/http-https-echo. 我交换了您部署的图像并修复了端口。您可以使用以下 yaml 文件自己测试入口:

#ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: xyz-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/use-regex: "true"
spec:
  rules:
    - host: xyz.com
      http:
        paths:
          - path: /admin/auth-db-gui
            backend:
              serviceName: auth-db-gui-service
              servicePort: 27017

注意端口的设置方式。servicePortin ingress 对应的服务是port27017。我更改了服务的目标端口,因为 echo-server 在 80 上工作

#sevice.yaml

apiVersion: v1
kind: Service
metadata:
  name: auth-db-gui-service
spec:
  selector:
    app: auth-db-gui
  ports:
    - name: auth-db-gui
      protocol: TCP
      port: 27017
      targetPort: 80
#deployment.yaml
 
apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth-db-gui-deployment
spec:
  selector:
    matchLabels:
      app: auth-db-gui
  template:
    metadata:
      labels:
        app: auth-db-gui
    spec:
      containers:
        - name: auth-db-gui
          image: mendhak/http-https-echo

请查看有关服务的文档以获取更多示例。

于 2021-04-30T06:08:11.443 回答