Dynamic proxy_pass in nginx to another pod in Kubernetes

后端 未结 2 1457
难免孤独
难免孤独 2021-02-08 06:26

I\'m trying to create an nginx proxy that forwards requests to / to http://. I first tried the following:



        
2条回答
  •  梦谈多话
    2021-02-08 06:59

    After much research and trial and error I managed to solve this. First I changed the pod specification to:

    spec:
      containers:
        - name: nginx
          image: "nginx:1.10.0"
          ports:
            - containerPort: 8080
              name: "external"
              protocol: "TCP"
        - name: dnsmasq
          image: "janeczku/go-dnsmasq:release-1.0.5"
          args:
            - --listen
            - "127.0.0.1:53"
            - --default-resolver
            - --append-search-domains
            - --hostsfile=/etc/hosts
            - --verbose
    

    then I also had to disable the ipv6 for the resolver in nginx:

    location ~ ^/(.+)$ {
            resolver 127.0.0.1:53 ipv6=off;
            set $backend "http://$1:80";
            proxy_pass $backend;
    }
    

    Then it works as expected!

提交回复
热议问题