How do I make a forward-proxy server on k8s and ALB(or NLB)?

1.1k Views Asked by At

I created forward proxy server on EKS pods behind ALB(created by AWS Load Balancer Controller). All pod can take a response through 8118 port through ALB.

The resources like pod and ingress looked good to me. Then I tried if the proxy server work well with curl -Lx k8s-proxy-sample-domain.ap-uswest-1.elb.amazonaws.com:18118 ipinfo.io

Normally, I get random ip address from ipinfo.io. But it didn't.... So, I also did port-forad. Like this:

kubectl port-forward specifi-pod 8118:8118

Then I re-try redirect access on my host address.

curl -Lx localhost:8118 ipinfo.io

In this case, it went well. I cannot catch the reason. What's the difference between THROUGH ALB and port-forward. Should I use NLB for some reason? Or some misconfigure?

My environement

  • k8s version: v1.18.2
  • node type: fargate

Manifest

Here is my manifest.

---
apiVersion: v1
kind: Namespace
metadata:
  name: tor-proxy
---
apiVersion: apps/v1
kind: Deployment
metadata:
  namespace: tor-proxy
  name: tor-proxy-deployment
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: tor-proxy
  replicas: 5
  template:
    metadata:
      labels:
        app.kubernetes.io/name: tor-proxy
    spec:
      containers:
      - image: dperson/torproxy
        imagePullPolicy: Always
        name: tor-proxy
        ports:
        - containerPort: 8118

---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: tor-proxy
  name: tor-proxy-service
  namespace: tor-proxy
spec:
  ports:
    - port: 18118
      targetPort: 8118
      protocol: TCP
  type: NodePort
  selector:
    app.kubernetes.io/name: tor-proxy
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  namespace: tor-proxy
  name: tor-proxy-ingress
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/scheme: internet-facing
    alb.ingress.kubernetes.io/target-type: ip
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 18118}]'
spec:
  rules:
    - http:
        paths:
          - path: /*
            backend:
              serviceName: tor-proxy-service
              servicePort: 18118
1

There are 1 best solutions below

1
On

Use NLB not ALB, because it pass the client IP toward a target site through proxy server.