簡體   English   中英

Kubernetes入口重寫問題

[英]Kubernetes ingress rewrite issue

我在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

您可以嘗試以下示例: 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 -

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM