N
N
noute2019-12-25 16:04:12
Nginx
noute, 2019-12-25 16:04:12

Kubernetes nginx reverseproxy how to deploy any examples?

Hello. I'm trying to deploy nginx reverseproxy in K8s. I have dotnet pods, I want to proxy them through nginx reverse proxy
. I don't understand how to do it.
Here is the config.
configmap
nginx.conf

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx
data:
  nginx.conf: |
    worker_processes 4;

    events { worker_connections 1024; }

    http {
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        default_type application/octet-stream;
        gzip on;

    upstream hosts {
             server ip:port;
             server ip:port;
                }
    server {
        listen 80;
        location / {
        proxy_pass http://hosts;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
         }

         }


         }

deployment nginx
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1
        ports:
        - name: http
          containerPort: 80
        volumeMounts:
        - name: nginx-config
          mountPath: /etc/nginx
      volumes:
        - name: nginx-config
          configMap:
            name: nginx

service nginx
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  type: LoadBalancer
  selector:
    app: nginx
  ports:
  - port: 80
    name: http
  externalIPs:
  - ip
  - ip

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Georg Gaal, 2020-02-02
@noute

Other things being equal, it is recommended to use ingress to publish a service in a kubernetes cluster to the outside. In fact, this will be nginx reverse proxy. One of the typical options:
https://github.com/kubernetes/ingress-nginx
https://kubernetes.github.io/ingress-nginx/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question