---
url: https://ibee.ai/docs/infrastructure/kubernetes/deploy-from-github-actions
last_updated: 2026-11-26
---

> For clean Markdown of any page, append .md to the page URL. For a complete documentation index, see https://ibee.ai/docs/llms.txt (full text of every page: https://ibee.ai/docs/llms-full.txt). For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://ibee.ai/docs/_mcp/server.

# Deploy to Kubernetes from GitHub Actions

> Deploy to your IBEE Kubernetes cluster from GitHub Actions with a dedicated service account limited to one namespace. Create the service account, role binding and token, build a CI kubeconfig, store it as a GitHub secret, and run kubectl or Helm in a workflow.

To deploy from GitHub Actions, give the workflow its own **service account** that can only change one namespace, and a kubeconfig that signs in with that service account's token. Don't use the kubeconfig you download from the portal: it has **full administrator access to the whole cluster**, and anyone who can read your CI secrets would get that access too.

You set this up once with the admin kubeconfig, then every workflow run uses the limited one.

## How it works

1. With the admin kubeconfig, you create a **namespace** for the app, a **service account** in it, a **RoleBinding** that grants the service account permissions in that namespace only, and a **token** for the service account.
2. You build a small kubeconfig from the cluster's API endpoint, its CA certificate and that token.
3. You store that kubeconfig as a GitHub Actions secret. The workflow writes it to a file and runs `kubectl` or `helm`.

## Before you begin

* A running cluster. On the cluster's **Overview** tab, under **Connection Details**, download the admin kubeconfig with **Kubeconfig** → **Download**.
* `kubectl` on your machine.
* Admin access to the GitHub repository, to add secrets. The [GitHub CLI](https://cli.github.com/) (`gh`) is optional.
* The GitHub Actions runner must be able to reach the cluster's **API endpoint**, shown under **Connection Details**. If the endpoint isn't reachable from GitHub-hosted runners, use a [self-hosted runner](https://docs.github.com/en/actions/hosting-your-own-runners) in a network that can reach it.

The examples use the namespace `example-app` and the service account `github-deployer`. Replace them with your own names.

## Steps

### Point kubectl at the admin kubeconfig

```bash
export KUBECONFIG=~/Downloads/PASTE-KUBECONFIG-FILE-NAME
kubectl get nodes
```

The command lists your cluster's nodes.

### Choose the permissions CI needs

Grant one of the built-in Kubernetes roles, through a RoleBinding so it applies to one namespace only:

| Role    | CI can                                                                                                                                                               | CI can't                                                                                   |
| ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| `edit`  | Create, change and delete most objects in the namespace: Deployments, StatefulSets, Services, ConfigMaps, Secrets, Ingresses, Jobs, CronJobs, PersistentVolumeClaims | Create Roles or RoleBindings; change anything in other namespaces or anything cluster-wide |
| `admin` | Everything `edit` can, plus Roles and RoleBindings in the namespace                                                                                                  | Change anything in other namespaces or anything cluster-wide                               |

Use `edit` unless your manifests or Helm charts create Roles or RoleBindings. Neither role can create namespaces, CustomResourceDefinitions (CRDs) or ClusterRoles. Install those once with the admin kubeconfig.

### Create the namespace, service account, role binding and token

**`github-deployer.yaml`**

```yaml title="github-deployer.yaml"
apiVersion: v1
kind: Namespace
metadata:
  name: example-app
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: github-deployer
  namespace: example-app
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: github-deployer
  namespace: example-app
subjects:
  - kind: ServiceAccount
    name: github-deployer
    namespace: example-app
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: edit # or admin, see the table above
---
apiVersion: v1
kind: Secret
metadata:
  name: github-deployer-token
  namespace: example-app
  annotations:
    kubernetes.io/service-account.name: github-deployer
type: kubernetes.io/service-account-token
```

```bash
kubectl apply -f github-deployer.yaml
```

Kubernetes fills the Secret with a token for the service account. This token doesn't expire. You replace it when you rotate it (see [Rotate or revoke the token](#rotate-or-revoke-the-token)).

To let the same service account deploy to more namespaces, add a RoleBinding like the one above in each of them. Keep `subjects[0].namespace` set to `example-app`, where the service account lives.

### Build the CI kubeconfig

These commands read the API endpoint and CA certificate from the admin kubeconfig, read the token, and write a new file, `github-deployer.kubeconfig`:

```bash
NAMESPACE=example-app
SA=github-deployer
OUT=github-deployer.kubeconfig

SERVER=$(kubectl config view --minify -o jsonpath='{.clusters[0].cluster.server}')
kubectl config view --raw --minify \
  -o jsonpath='{.clusters[0].cluster.certificate-authority-data}' | base64 --decode > ca.crt
TOKEN=$(kubectl -n "$NAMESPACE" get secret "$SA-token" -o jsonpath='{.data.token}' | base64 --decode)

kubectl --kubeconfig="$OUT" config set-cluster cluster --server="$SERVER" \
  --certificate-authority=ca.crt --embed-certs=true
kubectl --kubeconfig="$OUT" config set-credentials "$SA" --token="$TOKEN"
kubectl --kubeconfig="$OUT" config set-context ci --cluster=cluster --user="$SA" --namespace="$NAMESPACE"
kubectl --kubeconfig="$OUT" config use-context ci
rm ca.crt
```

> **Warning**
>
> `github-deployer.kubeconfig` contains the token. Treat it like a password: don't commit it, and delete it once it's stored in GitHub.

### Check what the new kubeconfig can do

```bash
kubectl --kubeconfig=github-deployer.kubeconfig auth can-i create deployments -n example-app
kubectl --kubeconfig=github-deployer.kubeconfig auth can-i create deployments -n kube-system
```

The first command prints `yes` and the second prints `no`.

### Store the kubeconfig as a GitHub secret

With the GitHub CLI, from inside your repository:

```bash
gh secret set KUBE_CONFIG < github-deployer.kubeconfig
```

Or in GitHub, open the repository's **Settings** → **Secrets and variables** → **Actions**, click **New repository secret**, name it `KUBE_CONFIG`, and paste the whole file.

To require approval before deploying, or to keep separate kubeconfigs for separate clusters, store the secret on a GitHub [environment](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment) instead (`gh secret set KUBE_CONFIG --env production < github-deployer.kubeconfig`) and add `environment: production` to the job.

Then delete the local copy:

```bash
rm github-deployer.kubeconfig
```

### Use it in a workflow

This workflow applies the manifests in `k8s/` on every push to `main` and waits for the rollout to finish:

**`.github/workflows/deploy.yml`**

```yaml title=".github/workflows/deploy.yml"
name: Deploy

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - uses: azure/setup-kubectl@v4

      - name: Configure kubeconfig
        env:
          KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
        run: |
          install -m 600 /dev/null "$RUNNER_TEMP/kubeconfig"
          printf '%s\n' "$KUBE_CONFIG" > "$RUNNER_TEMP/kubeconfig"
          echo "KUBECONFIG=$RUNNER_TEMP/kubeconfig" >> "$GITHUB_ENV"

      - name: Deploy
        run: |
          kubectl apply -n example-app -f k8s/
          kubectl rollout status deployment/web-api -n example-app --timeout=180s
```

Passing the secret through `env:` rather than writing `${{ secrets.KUBE_CONFIG }}` inside `run:` keeps it out of the generated script.

## Build, push and deploy an image

To build your image, push it to [Container Registry](/docs/infrastructure/container-registry) and roll it out in one workflow, add a **Pull and push** registry access token to the repository as `IBEE_REGISTRY_USERNAME` and `IBEE_REGISTRY_TOKEN`, then replace the **Deploy** step:

```yaml
      - uses: docker/login-action@v3
        with:
          registry: registry.ibee.ai
          username: ${{ secrets.IBEE_REGISTRY_USERNAME }}
          password: ${{ secrets.IBEE_REGISTRY_TOKEN }}

      - name: Build and push
        run: |
          docker build -t registry.ibee.ai/acme-prod/web-api:${{ github.sha }} .
          docker push registry.ibee.ai/acme-prod/web-api:${{ github.sha }}

      - name: Deploy
        run: |
          kubectl set image deployment/web-api \
            web-api=registry.ibee.ai/acme-prod/web-api:${{ github.sha }} -n example-app
          kubectl rollout status deployment/web-api -n example-app --timeout=180s
```

The cluster pulls the image with its own **Pull only** token, not the CI token. See [Pull private images in Kubernetes](/docs/infrastructure/kubernetes/pull-private-images).

### Deploy with Helm

Helm uses the same `KUBECONFIG`. Add `azure/setup-helm@v4` and run:

```bash
helm upgrade --install web-api ./chart --namespace example-app --wait
```

If the chart creates Roles or RoleBindings, bind `admin` instead of `edit`. If it installs CRDs, install them once with the admin kubeconfig.

## Verify

* The workflow run finishes and the **Deploy** step prints `deployment "web-api" successfully rolled out`.
* With the admin kubeconfig, `kubectl get deployments -n example-app` shows the new version.

## Rotate or revoke the token

To **rotate** the token, delete the token Secret, apply `github-deployer.yaml` again, rebuild the kubeconfig and update the `KUBE_CONFIG` secret in GitHub. The old token stops working when its Secret is deleted:

```bash
kubectl delete secret github-deployer-token -n example-app
kubectl apply -f github-deployer.yaml
```

To **revoke** CI's access entirely, delete the service account. Its token Secret and access go with it:

```bash
kubectl delete serviceaccount github-deployer -n example-app
```

## Troubleshooting

| You see                                                                                              | What it means                                                                                                                | What to do                                                                                                                   |
| ---------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `Unable to connect to the server` or `i/o timeout`                                                   | The runner can't reach the cluster's API endpoint                                                                            | Check the endpoint under **Connection Details**. If GitHub-hosted runners can't reach it, use a self-hosted runner that can. |
| `x509: certificate signed by unknown authority`                                                      | The kubeconfig is missing the cluster's CA certificate                                                                       | Rebuild it with `--embed-certs=true` as shown above.                                                                         |
| `error: You must be logged in to the server (Unauthorized)`                                          | The token was rotated or the service account was deleted                                                                     | Rebuild the kubeconfig and update the GitHub secret.                                                                         |
| `Forbidden: User "system:serviceaccount:example-app:github-deployer" cannot create resource "roles"` | The `edit` role can't create Roles or RoleBindings                                                                           | Bind `admin` instead of `edit`.                                                                                              |
| `Forbidden` for `namespaces`, `customresourcedefinitions` or `clusterroles`                          | Cluster-wide objects are outside the service account's namespace                                                             | Create them once with the admin kubeconfig.                                                                                  |
| `Forbidden` in another namespace                                                                     | The service account only has a RoleBinding in `example-app`                                                                  | Add a RoleBinding in that namespace.                                                                                         |
| The token in `github-deployer-token` is empty                                                        | The `kubernetes.io/service-account.name` annotation doesn't match the service account, or the Secret was created moments ago | Check the annotation, wait a few seconds and read the Secret again.                                                          |
| `ImagePullBackOff` after deploying                                                                   | The cluster can't pull your private image                                                                                    | See [Pull private images in Kubernetes](/docs/infrastructure/kubernetes/pull-private-images).                                |

## Related pages

* [Pull private images in Kubernetes](/docs/infrastructure/kubernetes/pull-private-images)
* [Container Registry](/docs/infrastructure/container-registry): store the images your workflow builds
* [Kubernetes with External Secrets](/docs/tools/secret-manager/kubernetes): sync app secrets into the cluster instead of applying them from CI