DEV Community

Cover image for Kubernetes: Set Image Action
Andri
Andri

Posted on

Kubernetes: Set Image Action

My Workflow

I have a workflow for work (private repo) that required setting images on Kubernetes clusters and the workflow file was getting harder and harder to read.

So I decided to create Kubernetes: Set Image that generates kubectl commands to help with changing images on deployments, and wait until the changes take effect.

I'll be using this for automatic environments, manual dispatch for more stable environments.

Features

  • Supports multiple deployments
  • Supports multiple containers per deployment
  • Groups deployment commands, so if you have two changes to one deployment, it will only run one kubectl line.
  • Wait until the cluster reports that the changes have been applied.

Submission Category:

DIY Deployments

Yaml File or Link to Code

The README has examples of how to use this action.

Example workflow

workflow.yml

on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    name: Testing
    steps:
      - name: Test our action
        uses: andrioid/gh-action-k8s-set-image
        with:
          namespace: "default"
          images: |
            deployment.example.backend=gcr.io/example/backend:latest
            deployment.example.frontend=gcr.io/example/frontend:latest
Enter fullscreen mode Exit fullscreen mode

Runs:

kubectl --namespace default set image deployment/example backend=gcr.io/example/backend:latest frontend=gcr.io/example/frontend:latest
kubectl --namespace default rollout status deployment/example
Enter fullscreen mode Exit fullscreen mode

Additional Resources / Info

Special thanks to:

Top comments (0)