1

我在 Kubernetes 中有一个入口定义。

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: dev
  annotations:
    kubernetes.io/ingress.class: nginx
    #nginx.ingress.kubernetes.io/use-regex: "true"

    nginx.ingress.kubernetes.io/rewrite-target: /


spec:
  tls:
  - hosts:
    - xyz.org
    secretName: ingress-tls
  rules:
  - host: xyz.org
    http:
      paths:
      - path: /configuration/*
        backend:
          serviceName: dummysvc
          servicePort: 80           

当我点击 url 时,我需要它:https://example.com/configuration/它应该转到服务作为响应发送的某个文件或某个实体,但这不会发生,它会给我一个错误页面“找不到网页”对于上述地址”这是入口的问题吗?

以下是我的服务规范:

apiVersion: v1
kind: Service
metadata:
  name: dummysvc
spec:
  #type: LoadBalancer
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: configurationservice

以下是我的部署规范

apiVersion: apps/v1
kind: Deployment
metadata:
  name: dummy-deployment
  labels:
    app: configurationservice
spec:
  replicas: 3
  selector:
    matchLabels:
      app: configurationservice
  template:
    metadata:
      labels:
        app: configurationservice
    spec:
      volumes:
        - name: appinsights
          secret:
            secretName: appinsightngm-secrets
        - name: cosmosdb
          secret:
            secretName: cosmosdbngm-secrets
        - name: blobstorage
          secret:
            secretName: blobstoragengm-secrets
        - name: azuresearch
          secret:
            secretName: azuresearchngm-secrets            
      containers:
      - name: configurationservice
        image: xyz.azurecr.io/xyz.configurationservice:develop
        imagePullPolicy: Always
        ports:
        - containerPort: 80
        volumeMounts:
          - name: appinsights
            mountPath: "/appinsights/"
            readOnly: true
          - name: cosmosdb
            mountPath: "/cosmosdb/"
            readOnly: true
          - name: blobstorage
            mountPath: "/blobstorage/"
            readOnly: true
          - name: azuresearch
            mountPath: "/azuresearch/"
            readOnly: true
---
apiVersion: v1
kind: Service
metadata:
  name: dummysvc
spec:
  #type: LoadBalancer
  type: NodePort
  ports:
  - port: 80
    targetPort: 80
    protocol: TCP
  selector:
    app: configurationservice
4

1 回答 1

2

你可以试试这个例子: https ://github.com/kubernetes/ingress-nginx/blob/master/docs/examples/rewrite/README.md#rewrite-target

$ echo "
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$1
  name: rewrite
  namespace: default
spec:
  rules:
  - host: rewrite.bar.com
    http:
      paths:
      - backend:
          serviceName: http-svc
          servicePort: 80
        path: /something/?(.*)
" | kubectl create -f -
于 2019-02-22T11:24:37.610 回答