How to redeploy google cloud platform using kubectl

3/4/2020

I'm trying to find a quick command to redeploy a pod in Kubernetes.

  1. Currently, I pushed my docker image to google cloud.
  2. Then I list my pods
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       
  1. I edit the deployment config kubectl edit deployment audit-server.
  2. Update/change the image name.
  3. Save and exit.

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)

-- RonPringadi
google-cloud-platform
kubectl
kubernetes

2 Answers

3/5/2020

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

-- mdaniel
Source: StackOverflow

3/5/2020

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.

-- KoopaKiller
Source: StackOverflow