I'm working on EKS AWS and stuck because when ever I want to deployment the same code again after some changes I have to delete the previous deployment and create with back with new image, after pulling the new image in ECR (kubectl delete abcproj.json) which destroys the old pods(load balancer) and creates new one in the result its always give me new external IP. I want to prevent this problem and cannot find proper solution on internet.
Thanks in Advance!
From Kubernetes point of view you could try to do the following:
LoadBalancer
that will point to your applicationExample with YAML
's:
Below is example deployment of hello application:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello
spec:
selector:
matchLabels:
app: hello
version: 1.0.0
replicas: 1
template:
metadata:
labels:
app: hello
version: 1.0.0
spec:
containers:
- name: hello
image: "gcr.io/google-samples/hello-app:1.0"
env:
- name: "PORT"
value: "50001"
Take a specific look on parts of matchLabels
.
LoadBalancer
that will point to your applicationBelow is example service that will give access to hello application:
apiVersion: v1
kind: Service
metadata:
name: hello-service
spec:
selector:
app: hello
ports:
- port: 50001
targetPort: 50001
type: LoadBalancer
Take once again a specific look on selector
. It will match the pods by label named app
with value of hello
.
You could refer to official documentation: HERE!
Apply both YAML
definitions and wait for ExternalIP
to be assigned. After that check if application works.
Output of web browser with old application version:
Hello, world!
Version: 1.0.0
Hostname: hello-549db57dfd-g746m
On this step you could try to:
kubectl apply -f DEPLOYMENT.yaml
on new version to apply the differencesDeployment
and create a new one in place of old one.In this step do not delete your existing LoadBalancer
.
Using example Deployment
above we could simulate a version change of your image by changing the:
image: "gcr.io/google-samples/hello-app:1.0"
to:
image: "gcr.io/google-samples/hello-app:2.0"
After that you can apply it or recreate your deployment.
LoadBalancer
should not have changed IP address as it's not getting recreated.
Output of web browser with new application version:
Hello, world!
Version: 2.0.0
Hostname: hello-84d554cbdf-rbwgx
Let me know if this solution helped you.