I'm trying to find a quick command to redeploy a pod in Kubernetes.
kubectl -n pringadi get pods
NAME READY STATUS RESTARTS AGE
audit-server-757ffd5dd-ztn5s 1/1 Running 0 38m
configs-service-75c98f68c7-q928q 1/1 Running 0 36m
kubectl edit deployment audit-server
.Kubernetes immediately recognizes the change and redeploy audit-server
.
Question: What if I pushed my docker image (a newer image) to google cloud with the same name (Step 4) and just want to redeploy the audit-server
based on the current image. Is there a command for that? It a tedious job to keep editing the deployment config (Step 3)
It's wholly unclear what you're trying to do, but taking a guess:
kubectl set image deploy audit-server "*=us.gcr.io/whatever/whateverelse:12345"
will bump the image in your deployment without having to invoke your editor
Alternatively, use something like skaffold or its competitors to continuously push and reload a Pod for development
You could simply use a deployment with the imagePullPolicy: Always
and kill your pod after make a change. it will force your deployment download the image again.
From Kubernetes Docs:
imagePullPolicy: Always
: the image is pulled every time the pod is started.
Example:
kubectl apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: my-app
image: nginx
ports:
- name: http
containerPort: 80
imagePullPolicy: Always
EOF
Then after pulled your image, delete the running pod, deployment will download the image again:
kubectl delete pods -l app=my-app
Check the new container:
kubectl get pods -l app=my-app
I hope that helps.