0

Circumstances:

  • Win 10 Pro
  • Docker Engine
  • WSL2
  • k3d version v5.5.1
  • k3s version v1.26.4-k3s1
  • local host file entry 127.0.0.1 to testcluster (only want to access it locally)
  • Cluster creation via: k3d cluster create -p "80:80@loadbalancer" --agents 3
  • IP of masternode also resolving to testcluster

My objectives:

  • Set up multi-node test cluster using k3d with one master node and three worker nodes. - done

  • Deploy a Nginx web server accessible at http://testcluster/webserver to the default nginx page. - here is my problem (only can resolve it correctly to http://testcluster/ instead of /webserver path [404 Not Found nginx error])

  • Deploy Go application "containous/whoami" in 6 instances load balanced accessible at http://testcluster/whoami - works like a charm on all 6 instances

Question:

How do I configure the ingress.yaml/nginx default.conf to resolve http://testcluster/webserver correctly?

YAMLS:

Traefik-ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - http:
      paths:
      - path: /webserver
        pathType: Prefix
        backend:
          service:
            name: nginx-service
            port:
              number: 80
      - path: /whoami
        pathType: Prefix
        backend:
          service:
            name: gowebapi
            port:
              number: 80

nginx:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
  type: LoadBalancer

etc/host/conf.d/default.conf file on serverlb container:

server {
    listen       80;
    server_name  localhost;

    location /webserver {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ =404;
    }

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
}
  • Tried different traefik specific annotations to rewrite the path within the ingress.yaml
  • Tried tricking the nginx default.conf into resolving any request/path to default page
  • Tried following Middleware in my ingress.yaml:
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: stripprefix
spec:
  stripPrefix:
    prefixes:
      - /webserver

maqz
  • 28
  • 5

0 Answers0