GithubHelp home page GithubHelp logo

onlykumarabhishek / k8s-set-context Goto Github PK

View Code? Open in Web Editor NEW

This project forked from josh-01/k8s-set-context

0.0 0.0 0.0 5.38 MB

GitHub Action for setting context before deploying to Kubernetes clusters

License: MIT License

JavaScript 29.42% TypeScript 70.58%

k8s-set-context's Introduction

Kubernetes set context

This action can be used to set cluster context before other actions like azure/k8s-deploy, azure/k8s-create-secret or any kubectl commands (in script) can be run subsequently in the workflow.

There are two approaches for specifying the deployment target:

  • Kubeconfig file provided as input to the action df
  • Service account approach where the secret associated with the service account is provided as input to the action

If inputs related to both these approaches are provided, kubeconfig approach related inputs are given precedence.

In both these approaches it is recommended to store these contents (kubeconfig file content or secret content) in a secret which could be referenced later in the action.

Action inputs

Action inputs Description
method
Method
(Optional) Acceptable values: kubeconfig/service-account. Default value: kubeconfig
kubeconfig
Kubectl config
(Relevant for kubeconfig approach) Contents of the configuration file to be used with kubectl (e.g. can be pulled from a secret)
context
Context
(Relevant for kubeconfig approach) Context to be used within the provided kubeconfig file
k8s-url
API server URL
(Relevant for service account approach) API Server URL for the K8s cluster
k8s-secret
Secret
(Relevant for service account approach) Secret associated with the service account to be used for deployments

Example usage

Kubeconfig approach

- uses: azure/k8s-set-context@v1
  with:
    method: kubeconfig
    kubeconfig: <your kubeconfig> # Use secret (https://developer.github.com/actions/managing-workflows/storing-secrets/)
    context: <context name>  #If left unspecified, current-context from kubeconfig is used as default
  id: setcontext

Please note that the input requires the contents of the kubeconfig file, and not its path.

Following are the ways to fetch kubeconfig file onto your local development machine so that the same can be used in the action input shown above:

For Azure Kubernetes Service cluster

az aks get-credentials --name
                       --resource-group
                       [--admin]
                       [--file]
                       [--overwrite-existing]
                       [--subscription]

Further details can be found in az aks get-credentials documentation.

For any generic Kubernetes cluster

Please refer to documentation on fetching kubeconfig for any generic K8s cluster

Service account approach

- uses: azure/k8s-set-context@v1
  with:
    method: service-account
    k8s-url: <URL of the clsuter's API server>
    k8s-secret: <secret associated with the service account>
  id: setcontext

For fetching Server URL, execute the following command on your shell:

kubectl config view --minify -o 'jsonpath={.clusters[0].cluster.server}'

For fetching Secret object required to connect and authenticate with the cluster, the following sequence of commands need to be run:

kubectl get serviceAccounts <service-account-name> -n <namespace> -o 'jsonpath={.secrets[*].name}'
kubectl get secret <service-account-secret-name> -n <namespace> -o yaml

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

k8s-set-context's People

Contributors

shashankbarsin avatar microsoftopensource avatar josh-01 avatar shigupt202 avatar thesattiraju avatar dependabot[bot] avatar rgsubh avatar anraghun avatar anumita avatar cmendesce avatar msftgits avatar stigok avatar sundargs2000 avatar

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.