How to make a pod accessible from outide with a Load Balancer (or directly)?

11/27/2020

Here is what I'm trying to do with a Kubernetes config file:

<!-- language: lang-yaml -->
apiVersion: apps/v1
kind: Deployment
metadata:
  name: selenium-hub
  labels:
    app: selenium-hub
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: selenium-hub
  template:
    metadata:
      labels:
        app: selenium-hub
    spec:
      containers:
      - name: selenium-hub
        image: selenium/hub
        ports:
          - containerPort: 4444
        resources:
          limits:
            memory: "1000Mi"
            cpu: ".5"
        livenessProbe:
          httpGet:
            path: /wd/hub/status
            port: 4444
          initialDelaySeconds: 30
          timeoutSeconds: 5
        readinessProbe:
          httpGet:
            path: /wd/hub/status
            port: 4444
          initialDelaySeconds: 30
          timeoutSeconds: 5
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  externalTrafficPolicy: Local
  ports:
  - name: http
    port: 4444
    protocol: TCP
    targetPort: 4444
  selector:
    app: selenium-hub
  type: LoadBalancer

In GKE it creates an app with a pod, then a Load Balancer with an external IP. But when I'm trying to access the app from outside through http://LBIP:port it doesn't work.

So how I can expose the pod I created in first place? Do I need a LB if I'm using only one replica?

-- jscoys
google-kubernetes-engine
kubernetes
load

2 Answers

11/29/2020

Hum well... hum... you'll laugh! On my side I didn't laugh...

It was a network issue. Don't know why but my house IP address seems to be, for an obscure reason, blacklisted from accessing any instances on GCP. The console no issue, but when trying to go through the http via my browser it doesn't connect at all.

Use of a nordvpn is working! So far so good.

Anyway thx for you help guys!

-- jscoys
Source: StackOverflow

11/27/2020

Looking at specs, I don't see any problem. Check few things - 1. Does your pod is in Running state with exposed port 4444? 2. Can you access your pod locally using ClusterIP:port?

You can expose your pod using NodePort service also but in production NodePort service is not a recommended way to expose app to outside cluster.

-- Rushikesh
Source: StackOverflow