Skip to content

Pablommr/kubernetes-eks

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kubernetes-eks

Action to apply artifacts files in your EKS cluster.

This action allows you to apply Kubernetes artifact files by simply pointing to the path where your file is located.


Example

name: Build

on:
  push:
    branches: [ main ]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 
        uses: actions/checkout@v4
      - name: Deployment
        uses: Pablommr/[email protected]
        env:
          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          KUBECONFIG: ${{ secrets.KUBECONFIG }}
          KUBE_YAML: path_to_file/file.yml

Usage

To use this action, you just need a user that has permission to apply artifacts in your EKS cluster. For more information, see this link. Also, set up the necessary environment variables listed below.


ENV's

Required

AWS_ACCESS_KEY_ID

AWS access key id for IAM role.

AWS_SECRET_ACCESS_KEY

AWS secret key for IAM role.

KUBECONFIG

Environment variable containing the base64-encoded kubeconfig data. Pay attention to the profile name; it must match the AWS_PROFILE_NAME.

KUBE_YAML or FILES_PATH

One of them (or both) must be set.

KUBE_YAML is the path of file to file used to create/update the resource. This env can be an array with more then 1 file. (I.e. kubernetes/deployment.yml,artifacts/configmap.yaml )

FILES_PATH is the path of the directory where the files are located. All files in this current directory will be applied.

The files must be with *.yaml or *.yml extensions.


Optional

AWS_PROFILE_NAME

Profile name to be configured. If not passed, this env assume the value 'default'

ENVSUBST

(boolean)

Whether to run envsubst to substitute environment variables inside the file in KUBE_YAML. Your variable inside your file need begin with "$". If not passed, this env assume the value 'false'

SUBPATH

(boolean)

If you use path in env FILES_PATH, you can set this env to true to apply files in subdirectory. Default value is false.

CONTINUE_IF_FAIL

(boolean)

If you use path in env FILES_PATH, you can set this env to true to continue applying files in case of fail in one file. Default value is false.

KUBE_ROLLOUT

(boolean)

Whether to watch the status of the latest rollout until it's done. The rollout only works for Deployment, StatefulSet, or DaemonSet resources and will only be executed if the Pods applied by KUBE_YAML finalize with an unchanged status. Default value is true.

KUBE_ROLLOUT_TIMEOUT

(String)

Timeout to KUBE_ROLLOUT. This env must be in time format. (i.e.: 60s, 5m, 1h) and KUBE_ROLLOUT must be true. Defaul value is 20m.


Use case

Let's suppose you need to apply three artifacts in your EKS: one Deployment, one Service, and one ConfigMap. All your Kubernetes artifacts are inside the kubernetes folder, like this:

├── README.md
├── app
|  └── files
├── kubernetes
│   ├── deployment.yaml
│   ├── envs
│   │   ├── prod
│   │   │   └── configmap.yaml
│   │   └── staging
│   │       └── configmap.yaml
│   └── service.yaml
└── another_files

You've already set up your build and just need to apply it in Kubernetes. Even if the only change was in the ConfigMap, you will need to roll out the pods. You want to apply just the prod ConfigMap, and you also need to substitute variables inside deployment.yml for some other value. Let's assume you want to change the image tag, so you can name your tag in the image line in deployment.yml with a placeholder, for example $IMAGE_TAG, like this:

image: nginx:$IMAGE_TAG

Then, pass the IMAGE_TAG as an environment variable with the desired value.

You can configure your pipeline like this:

name: Build

on:
  push:
    branches: [ main ]

  workflow_dispatch:

env:
  AWS_PROFILE_NAME: default
  AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
  AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
  KUBECONFIG: ${{ secrets.KUBECONFIG }}

jobs:
  deploy:
    runs-on: ubuntu-latest
    needs: build_and_push
    steps:
      - name: Checkout 
        uses: actions/checkout@v4
      - name: Deploy
        uses: Pablommr/[email protected]
        env:
          FILES_PATH: kubernetes
          KUBE_YAML: kubernetes/envs/prod/configmap.yaml
          SUBPATH: false #Defaul value
          ENVSUBST: true
          KUBE_ROLLOUT: true
          IMAGE_TAG: 1.21.6

In this setup, with FILES_PATH: kubernetes, you will apply all files under the kubernetes path (deployment.yaml and service.yaml), but none under env, since SUBPATH is set to false. However, you will still apply the ConfigMap with KUBE_YAML: kubernetes/envs/configmap.yaml.


Change Log

v2.1.1

  • Add to broke pipeline in case of rollout failed

v2.1.0

  • Add KUBE_ROLLOUT_TIMEOUT option
  • Alignment output logs
  • Fix KUBE_YAML files

v2.0.2

  • Fix files validation in SUBPATH

v2.0.1

  • Fix to get resource name
  • Add yq in background

v2.0.0

  • Added possibilitie to add path (env FILES_PATH) to apply multiple files
  • Added env SUBPATH to apply files in supath
  • Added env CONTINUE_IF_FAIL to continue applying files in fail case
  • Added output on github action page

v1.2.0

  • Changed strategy to use an image that has already been built with dependencies in public registry kubernetes-eks, decreasing action execution time

v1.1.0

  • Added otpion to KUBE_ROLLOUT follow the rollout status in Action page
  • Fix metacharacter replacement in ENVSUBST

v1.0.0

  • Project started