Reputation: 325
I have existing deployments in k8s, I would like to update container, I updated docker image tag (new unique id) in deployment and run:
kubectl apply -f testdeploy.yml --namespace=myapp
Output is: deployment.apps/fakename configured
But nothing happens.
When I run kubectl get pods --namespace=myapp
I can see only one old pod with old age.
Sometimes is working, sometimes not, why?
What is wrong?
Upvotes: 5
Views: 4229
Reputation: 143
You need to delete your deployment kubectl delete -f testdeploy.yml --namespace=myapp
and then create it again kubectl apply -f testdeploy.yml --namespace=myapp
it will fetch the new image, or you can edit your deployment file as shown below and introduce rollingupdate and then when you update your image you can simply type kubectl rollout restart deploy deployment_name_mentioned_in_manifest -n namespace
this will provision a new pod while the old stays and fetch the new image, once that is done old pod will get deleted and the new pod will have the latest image.
Example with the manifest file below if i want to pull latest image i will type kubectl rollout restart deploy nginx -n test
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: test
spec:
replicas: 1
selector:
matchLabels:
name: nginx
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template:
metadata:
labels:
name: nginx
spec:
containers:
- name: nginx
image: nginx:latest
imagePullPolicy: Always
ports:
- containerPort: 80
hostPort: 80
- containerPort: 443
hostPort: 443
readinessProbe:
tcpSocket:
port: 443
port: 80
initialDelaySeconds: 5
periodSeconds: 5
Upvotes: -2
Reputation: 55
try describing the deployment and see the events
kubectl describe <deployment-name> --namespace=myapp
or
kubectl get events --namespace=myapp
to understand what is happening.
try checking whether new replicas has been created for changed deployment container image.
kubectl get rs -n myapp
check the number of replicas expected example when you do kubectl get rs
:
NAME DESIRED CURRENT READY AGE
<deployment-name>-58ffbb8b76 0 0 0 10s
maybe few more details would be helpful to understand why was nothing happening when you try to deploy.
kubernetes has nice documentation check this.
https://kubernetes.io/docs/tasks/debug-application-cluster/debug-application-introspection/
Upvotes: 4
Reputation: 1271
Try with adding ImagePullPolicy: Always
as the below:
spec:
containers:
- image: <YOUR_IMAGE>:<YOUR_TAG>
imagePullPolicy: Always
Upvotes: 3