-1

I deployed a web server on a pod and created a load balancing service like this kubectl expose deployment api --port=80 --target-port=8080 --name api-LB --type=LoadBalancer

However when I re-deployed the pod, let's say with some updates, it seems that loses the binding with the LoadBalancer. So I have to create a loadbalancing service from the top so to get an external ip.

I would like to ask, if there is a way to bind the Load Balancer and the pod so there won't be any need for exposing the pod to the loadbalancer each time new pod deployments are performed.

API development yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-dev
  namespace: default
spec:
  template:
    metadata:
      name: api-dev

    spec:
      volumes:
      - name: nfs-volume
        nfs:
          # URL for the NFS server
          server: xxxx
          path: xxxx

      containers:
      - name: api-dev
        image: docker-image-at-registry
        ports:
          - containerPort: 80
            name: server

        volumeMounts:
          - name: nfs-volume
            mountPath: /var/nfs

      imagePullSecrets:
        - name: regcred

  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: api-dev

  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
Ioan Kats
  • 523
  • 1
  • 7
  • 19
  • Can you share file yaml of development api? – quoc9x Nov 23 '21 at 07:53
  • Which version of Kubernetes did you use and how did you set up the cluster? Did you use bare metal installation or some cloud providor? It is important to reproduce your problem. – Mikołaj Głodziak Nov 23 '21 at 11:00
  • Hello @MikołajGłodziak, I am using VMware's PKS. NVM I found a solution with deploying a load balancer service for a specific application. Thanks for your time tho :) – Ioan Kats Mar 15 '22 at 22:02

1 Answers1

0

You have to add the label in deploymet api?
Something look like:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-dev
  namespace: default
spec: 
  template:
    metadata:
      name: api-dev
      labels:
        app: api-dev

    spec:
      volumes:
      - name: nfs-volume
        nfs:
          # URL for the NFS server
          server: xxxx
          path: xxxx

      containers:
      - name: api-dev
        image: docker-image-at-registry
        ports:
          - containerPort: 80
            name: server

        volumeMounts:
          - name: nfs-volume
            mountPath: /var/nfs

      imagePullSecrets:
        - name: regcred

  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: api-dev
      app: api-dev

  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0

Then, try this

kubectl expose deployment api --port=80 --target-port=8080 --name api-LB --type=LoadBalancer --selector=app=api-dev
quoc9x
  • 1,423
  • 2
  • 9
  • 26