{"id":15478490,"url":"https://github.com/azure/k8s-set-context","last_synced_at":"2025-05-16T07:06:34.276Z","repository":{"id":36993143,"uuid":"206293113","full_name":"Azure/k8s-set-context","owner":"Azure","description":"GitHub Action for setting context and retrieving Kubeconfig before deploying to Kubernetes clusters","archived":false,"fork":false,"pushed_at":"2025-05-13T19:17:41.000Z","size":35892,"stargazers_count":92,"open_issues_count":5,"forks_count":37,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-05-13T20:41:48.433Z","etag":null,"topics":["action","actions","azure","github-action","github-actions","k8s","kubeconfig","kubernetes"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Azure.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-09-04T10:26:44.000Z","updated_at":"2025-05-13T19:17:39.000Z","dependencies_parsed_at":"2024-06-18T12:33:58.960Z","dependency_job_id":"c58cb242-e598-477f-b888-4531e85f8e46","html_url":"https://github.com/Azure/k8s-set-context","commit_stats":{"total_commits":81,"total_committers":22,"mean_commits":"3.6818181818181817","dds":0.7530864197530864,"last_synced_commit":"2beb148ddce07e99dd289f7e0008a4701ddf89bb"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fk8s-set-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fk8s-set-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fk8s-set-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Azure%2Fk8s-set-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Azure","download_url":"https://codeload.github.com/Azure/k8s-set-context/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254092647,"owners_count":22013290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["action","actions","azure","github-action","github-actions","k8s","kubeconfig","kubernetes"],"created_at":"2024-10-02T04:04:52.052Z","updated_at":"2025-05-16T07:06:29.265Z","avatar_url":"https://github.com/Azure.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Kubernetes set context\n\nThis action can be used to set cluster context before other actions like [`azure/k8s-deploy`](https://github.com/Azure/k8s-deploy/tree/master) and [`azure/k8s-create-secret`](https://github.com/Azure/k8s-create-secret/tree/master). It should also be used before `kubectl` commands (in script) are run subsequently in the workflow.\n\nIt is a requirement to use [`azure/login`](https://github.com/Azure/login/tree/master) in your workflow before using this action when using the `service-account` or `service-principal` methods.\n\nThere are three approaches for specifying the deployment target:\n\n- Kubeconfig file provided as input to the action\n- Service account approach where the secret associated with the service account is provided as input to the action\n- Service principal approach (only applicable for arc cluster) where service principal provided with 'creds' is used as input to action\n\nIn all these approaches it is recommended to store these contents (kubeconfig file content or secret content) in a [secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets/).\n\nRefer to the [action metadata file](./action.yml) for details about inputs. Note that different inputs are required for different method and cluster types. Use the below examples as a reference.\n\n## Example usage\n\n### Kubeconfig approach\n\n```yaml\n- uses: azure/k8s-set-context@v4\n  with:\n     method: kubeconfig\n     kubeconfig: \u003cyour kubeconfig\u003e\n     context: \u003ccontext name\u003e # current-context from kubeconfig is used as default\n```\n\n**Please note** that the input requires the _contents_ of the kubeconfig file, and not its path.\n\nFollowing 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.\n\n#### Azure Kubernetes Service cluster\n\n```bash\naz aks get-credentials --name\n                       --resource-group\n                       [--admin]\n                       [--file]\n                       [--overwrite-existing]\n                       [--subscription]\n```\n\nFurther details can be found in [az aks get-credentials documentation](https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az-aks-get-credentials).\n\n#### Generic Kubernetes cluster\n\nPlease refer to documentation on fetching [kubeconfig for any generic K8s cluster](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/)\n\n### Service account approach\n\n```yaml\n- uses: azure/k8s-set-context@v4\n  with:\n     method: service-account\n     k8s-url: \u003cURL of the cluster's API server\u003e\n     k8s-secret: \u003csecret associated with the service account\u003e\n```\n\nFor fetching Server URL, execute the following command on your shell:\n\n```bash\nkubectl config view --minify -o 'jsonpath={.clusters[0].cluster.server}'\n```\n\nFor fetching Secret object required to connect and authenticate with the cluster, the following sequence of commands need to be run:\n\n```bash\nkubectl get serviceAccounts \u003cservice-account-name\u003e -n \u003cnamespace\u003e -o 'jsonpath={.secrets[*].name}'\n\nkubectl get secret \u003cservice-account-secret-name\u003e -n \u003cnamespace\u003e -o yaml\n```\n\n### Service account approach for arc cluster\n\n```yaml\n- uses: azure/k8s-set-context@v4\n  with:\n     method: service-account\n     cluster-type: arc\n     cluster-name: \u003ccluster-name\u003e\n     resource-group: \u003cresource-group\u003e\n     token: '${{ secrets.SA_TOKEN }}'\n```\n\n### Service principal approach for arc cluster\n\n```yaml\n- uses: azure/k8s-set-context@v4\n  with:\n     method: service-principal\n     cluster-type: arc\n     cluster-name: \u003ccluster-name\u003e\n     resource-group: \u003cresource-group\u003e\n```\n\n## Contributing\n\nThis project welcomes contributions and suggestions. Most contributions require you to agree to a\nContributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us\nthe rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.\n\nWhen you submit a pull request, a CLA bot will automatically determine whether you need to provide\na CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions\nprovided by the bot. You will only need to do this once across all repos using our CLA.\n\nThis project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).\nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or\ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure%2Fk8s-set-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fazure%2Fk8s-set-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fazure%2Fk8s-set-context/lists"}