Skip to content

tvarohohlavy/kubectl-action

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kubectl Action

I archived this repository because I think there are now more appropriate options like helm and argocd

This action allows you to deploy to a kubernetes cluster.

Alternatives:

Inputs

kubeconfig

Base64 encoded .kube/config file, to generate use:

cat .kube/config | base64

Outputs

output

kubectl commands output

Usage

Kustomize a Deployment

- name: Kustomize
  uses: danielr1996/[email protected]
  with:
    args: kustomize deployment/overlays/replace > template.yaml

Deploy a Deployment

- uses: danielr1996/[email protected]
  name: Deploy
  with:
    kubeconfig: ${{ secrets.KUBE_CONFIG }}
    args: apply -f deployment.yaml

Multiple kubectl commands

- uses: danielr1996/[email protected]
  name: Deploy
  with:
    kubeconfig: ${{ secrets.KUBE_CONFIG }}
    args: |
      create namespace my-namespace
      delete secret -n my-namespace secret-credentials --ignore-not-found
      create secret -n my-namespace generic secret-credentials \
                    --from-literal=USERNAME=${{secrets.USERNAME}} \
                    --from-literal=PASSWORD=${{secrets.PASSWORD}}
      apply -f deployment.yaml

Outputs usage

  scale_down:
    runs-on: [ self-hosted ]
    outputs:
     replicas: ${{ steps.get_replicas.outputs.output }}
    steps:
    - name: get replicas count
      id: get_replicas
      uses: danielr1996/[email protected]
      with:
        kubeconfig: ${{ secrets.KUBECONFIG }}
        args: |
          get deployments.apps app -o jsonpath='{.spec.replicas}'
    - name: scale down to 0 replicas
      uses: danielr1996/[email protected]
      with:
        kubeconfig: ${{ secrets.KUBECONFIG }}
        args: |
          scale --replicas=0 deployment app

  scale_up:
    runs-on: [ self-hosted ]
    needs: [ scale_down ]
    steps:          
    - name: create environmental variable
      run: |
        echo "REPLICAS=${{ needs.scale_down.outputs.replicas }}" | tr -d "'" >> $GITHUB_ENV
        
    - name: scale up to original number of replicas
      uses: danielr1996/[email protected]
      with:
        kubeconfig: ${{ secrets.KUBECONFIG }}
        args: |
          scale --replicas=${{ env.REPLICAS }} deployment app

About

Github Action for kubectl

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dockerfile 58.8%
  • Shell 41.2%