kubectl commands directly in GitHub Actions workflows for push-based deployment instead of GitOps tools like ArgoCD or FluxCD. To authenticate to a Kubernetes cluster, you need a Kubeconfig file. However, setting it up as a GitHub Actions secret can cause issues due to base64 encoding of multi-line strings.
apiVersion: v1
kind: Config
clusters:
- name: production
cluster:
server: https://<cluster-ip>:<port>
certificate-authority: |
<base64-encoded-ca-certificate>
contexts:
- name: prod@production
context:
cluster: production
user: prod
users:
- name: prod
user:
token: |
<access-token>
The
| character on the certificate-authority and token lines indicates a multi-line string. When base64 encodes the file, it converts newline characters to \n, which breaks the Kubeconfig when decoded. You must fix this before storing the file as a secret.When using single-line strings, make sure to replace all newline characters with no spaces in between for the
base64-encoded-ca-certificate and access-token values.