Coder Social home page Coder Social logo

kubectl-action's Introduction

kubectl-action

GitHub Action to manage a K8s (Kubernetes) cluster using kubectl.

Usage

To use this action, add the following step to your GitHub Action workflow:

- uses: tale/kubectl-action@v1
  with:
    base64-kube-config: ${{ secrets.KUBE_CONFIG }}

Keep in mind that the action expects a base64 encoded string of your Kubernetes configuration. The simplest way to do that is to run cat $HOME/.kube/config | base64 and save that output as an action secret. It's additionally possible to generate a config file using the aws CLI for EKS or any other tools with other cloud providers.

It's also possible to specify the version of the kubectl CLI to use. The current default release used by this action is the latest version.

- uses: tale/kubectl-action@v1
  with:
    base64-kube-config: ${{ secrets.KUBE_CONFIG }}
    kubectl-version: v1.22.0

Once you've completed this setup, you have direct access to the kubectl binary and command in the rest of your actions. Here's a full example to give you some inspiration:

name: Kubectl Action

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: tale/kubectl-action@v1
      with:
        base64-kube-config: ${{ secrets.KUBE_CONFIG }}
    - run: kubectl get pods

Here's an example using AWS EKS:

name: Kubectl Action

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Configure AWS Credentials
      uses: aws-actions/configure-aws-credentials@v4
      with:
        role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
        aws-region: us-east-2
    - name: Generate kubeconfig
      run: |
        {
            echo 'EKS_CREDS<<EOF'
            aws eks update-kubeconfig --region us-east-2 --name my-cluster --dry-run | base64
            echo EOF
        } >> $GITHUB_ENV
    - uses: tale/kubectl-action@v1
      with:
        base64-kube-config: ${{ env.EKS_CREDS }}
    - run: kubectl get pods

kubectl-action's People

Contributors

tale avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

kubectl-action's Issues

Not using input.kubectl-version

Trying to fix the kubectl version to 1.23.4 to workround aws/aws-cli#6920

But getting the following error in the logs:

Run tale/[email protected]
  with:
    base64-kube-config: ***
    kubectl-version: v1.23.4
  env:
    AWS_DEFAULT_REGION: eu-west-1
    AWS_REGION: eu-west-1
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***
Run echo "/home/runner/work/_actions/tale/kubectl-action/v1.0.2" >> $GITHUB_PATH
  echo "/home/runner/work/_actions/tale/kubectl-action/v1.0.2" >> $GITHUB_PATH
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    AWS_DEFAULT_REGION: eu-west-1
    AWS_REGION: eu-west-1
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***
Run setup-kubectl.sh
  setup-kubectl.sh
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    AWS_DEFAULT_REGION: eu-west-1
    AWS_REGION: eu-west-1
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***
/home/runner/work/_actions/tale/kubectl-action/v1.0.2/setup-kubectl.sh: line 3: [https://dl.k8s.io/release/${{](https://dl.k8s.io/release/$%7B%7B) inputs.kubectl-version }}/bin/linux/amd64/kubectl: bad substitution
/home/runner/work/_actions/tale/kubectl-action/v1.0.2/setup-kubectl.sh: line 4: [https://dl.k8s.io/${{](https://dl.k8s.io/$%7B%7B) inputs.kubectl-version }}/bin/linux/amd64/kubectl.sha256: bad substitution
cat: kubectl.sha256: No such file or directory
sha256sum: 'standard input': no properly formatted SHA256 checksum lines found
mv: cannot stat 'kubectl': No such file or directory
Run login-kubectl.sh
  login-kubectl.sh
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
  env:
    AWS_DEFAULT_REGION: eu-west-1
    AWS_REGION: eu-west-1
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***
    BASE64_KUBE_CONFIG: ***

It's not downloading the version I'm asking for (and appears to be using the newer bundled version.

Where did the `dist` folder go?

Context

I updated the action from @v1 to @v1.3.0 and got the following error message:

Error: File not found: '/home/runner/_work/_actions/tale/kubectl-action/v1.3.0/dist/index.js'

I observed in the main branch that the dist folder isn't mapped anymore, but is referred in the action.yaml file (dist/index.js)

How to reproduce the error

I was using the action like this and just updated it to use node 20 and remove Github Actions WARNING messages.

      - name: kubectl config
        uses: tale/[email protected]
        with:
          base64-kube-config: ${{ steps.kubeconfig.outputs.KUBE_CONFIG_CONTENT }}
          kubectl-version: v${{ inputs.kubernetes-cluster-version }}

Coming back to v1 resolved the issue, but v1.3.0 tag and main branch should be updated.

Unable to process file command 'env' successfully. Error: Invalid format

Hi.
What I'm doing wrong here?

My Workflow:

      # setup 'env.AWS_*' variables to run Terraform
      - name: "Setup: Configure AWS credentials"
        uses: aws-actions/configure-aws-credentials@v4
        with:
          role-to-assume: ${{ inputs.aws-iam-role }}
          role-session-name: github-actions-terraform
          role-duration-seconds: 900
          aws-region: us-east-1

      - name: "Setup: Generate kubeconfig"
        run: echo "EKS_CREDS=$(aws eks update-kubeconfig --region ${{ inputs.aws-region }} --name ${{ inputs.aws-eks-cluster }}  --dry-run | base64)" >> $GITHUB_ENV

      - name: "Test: Check Kubernetes Pods"
        uses: tale/kubectl-action@v1
        with:
          base64-kube-config: ${{ env.EKS_CREDS }}
      - run: kubectl get pods -n ${{ inputs.helm-namespace }}

(btw, I've added closing " in the echo "EKS_CREDS=$(...)" command)

But it gives an error:

Run echo "EKS_CREDS=$(aws eks update-kubeconfig --region us-east-1 --name atlas-eks-ops-1-28  --dry-run | base64)" >> $GITHUB_ENV
  echo "EKS_CREDS=$(aws eks update-kubeconfig --region us-east-1 --name atlas-eks-ops-1-28  --dry-run | base64)" >> $GITHUB_ENV
  shell: /usr/bin/bash -e {0}
  env:
    grafana_client_secret: ***
    alertmanager_opsgenie_api_key: ***
    vmauth_password: ***
    notion_secret: ***
    redshift_secret: 
    AWS_DEFAULT_REGION: us-east-1
    AWS_REGION: us-east-1
    AWS_ACCESS_KEY_ID: ***
    AWS_SECRET_ACCESS_KEY: ***
    AWS_SESSION_TOKEN: ***
  
Error: Unable to process file command 'env' successfully.
Error: Invalid format 'cml0eS1kYXRhOiBMUzB0TFMxQ1JVZEpUaUJEUlZKVVNVWkpRMEZVUlMwdExTMHRDazFKU1VSQ1ZF'

Process Completed with exit code 127

I'm trying to use this action but I'm receiving this error:

Run tale/kubectl-action@v1
  with:
    base64-kube-config: ***
    kubectl-version: v1.[2](https://github.com/js-sites/api-gateway/runs/6149314144?check_suite_focus=true#step:2:2)[3](https://github.com/js-sites/api-gateway/runs/6149314144?check_suite_focus=true#step:2:3).0
Run setup-kubectl.sh
  setup-kubectl.sh
  shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
/home/runner/work/_temp/1[4](https://github.com/api-gateway/runs/6149314144?check_suite_focus=true#step:2:4)6973f[5](https://github.com/api-gateway/runs/6149314144?check_suite_focus=true#step:2:5)-5949-4bc2-b8c5-4f[6](https://github.com/api-gateway/runs/6149314144?check_suite_focus=true#step:2:6)ea45682c3.sh: line 1: setup-kubectl.sh: command not found
Error: Process completed with exit code 12[7](https://github.com/api-gateway/runs/6149314144?check_suite_focus=true#step:2:7).

Issues with new V1 - what tag was v1 before Feb 3rd, 2024?

Dear developers,

We have some trouble using these actions, and after multiple, multiple tests, I'd like to ask what version and/or commit v1 was before the weekend?

I have tried until Jan 2023, but it keep failing with:

File not found: '/home/github/actions-runner/_work/_actions/tale/kubectl-action/<….>/dist/index.js'

Thank you very much for your super excellent job and your help :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.