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