Kubernetes Ingress can not access container by path

8/30/2020

I am new to Kubernetes, I configured a Ingress and want to access container by minikube ip/path, but it failed to connect.

However, I could access it by using host instead of path, so I thought the problem might be Ingress.

I have no idea how to do, hope someone can help me. Thanks.

Here's my Deployment, Service and Ingress yaml file.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: portainer-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: portainer
  template:
    metadata:
      labels:
        app: portainer
    spec:
      containers:
      - name: portainer
        image: portainer/portainer:latest
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 9000
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: rancher-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: rancher
  template:
    metadata:
      labels:
        app: rancher
    spec:
      containers:
      - name: rancher
        image: rancher/server:latest
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 8080
apiVersion: v1
kind: Service
metadata:
  name: portainer-service
spec:
  selector:
    app: portainer
  type: NodePort
  ports:
  - port: 80
    targetPort: 9000
---
apiVersion: v1
kind: Service
metadata:
  name: rancher-service
spec:
  selector:
    app: rancher
  type: NodePort
  ports:
  - port: 80
    targetPort: 8080
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: path-based-ingress
spec:
  rules:
  - http:
      paths:
      - path: /portainer
        backend:
          serviceName: portainer-service
          servicePort: 80
      - path: /rancher
        backend:
          serviceName: rancher-service
          servicePort: 80
-- tienyulin
kubernetes
kubernetes-ingress

1 Answer

8/30/2020

Add this to your ingress in metadata section

annotations:
  nginx.ingress.kubernetes.io/rewrite-target: /
-- Dashrath Mundkar
Source: StackOverflow