This action logs in to Rancher and generate a token which can be used to access a Rancher managed kubernetes cluster.
Required: Rancher cluster name.
Required: FQDN for the Rancher managment server.
Required: AD account username.
Required: AD account password.
temporary_kube_token
: A temporary token that you can use to run kubectl which will be expired (usually after 24 hours).
- id: generate-rancher-auth
uses: <replace with github repo>/login-rancher
name: Login
with:
cluster_name: workload_cluster_1
rancher_server: rancher.example.com
username: ${{ secrets.RANCHER_USER }}
password: ${{ secrets.RANCHER_PASS }}
name: Test kubectl running Action
on:
push:
branches:
- main
jobs:
login:
name: Generate token to access clusters
runs-on: [......]
steps:
- uses: actions/checkout@v4
name: Checkout
- id: generate-rancher-auth
uses: <replace with github repo>/login-rancher
name: Login
with:
cluster_name: workload_cluster_1
rancher_server: rancher.example.com
username: ${{ secrets.RANCHER_USER }}
password: ${{ secrets.RANCHER_PASS }}
- name: Setup Kubectl
uses: azure/setup-kubectl@v4
with:
version: 'v*'
- name: Check namespace in the cluster with token and default rancher server
run: |
kubectl get namespace \
--token=${{ steps.generate-rancher-auth.outputs.kube_token }} \
--server=${{ steps.generate-rancher-auth.outputs.kubeapi_server }}
- name: Check namespace in the cluster with token and Authorized Cluster Endpoints server
run: |
kubectl get namespace \
--token=${{ steps.generate-rancher-auth.outputs.kube_token }} \
--server=${{ steps.generate-rancher-auth.outputs.kubeapi_server_ace }}
- name: Check namespace in the cluster with temporary token and default rancher server
run: |
kubectl get namespace \
--token=${{ steps.generate-rancher-auth.outputs.temporary_kube_token }} \
--server=${{ steps.generate-rancher-auth.outputs.kubeapi_server }}
We recommand to use token and server as the examples above but using the kubeconfig is also a possible option.
- name: Check namespace in the cluster with kubeconfig
run: |
echo ${{ steps.generate-rancher-auth.outputs.kubeconfig_base64 }} | base64 -d > kubeconfig
export KUBECONFIG=./kubeconfig
kubectl get namespace