Connecting with kubectl
This guide walks you through connecting to Runway staging and production
Kubernetes clusters so you can query the Kubernetes API with kubectl. Access goes
through the
GitLab Agent for Kubernetes (KAS)
proxy hosted on ops.gitlab.net. You do not need direct network access or a
cloud provider login.
Prerequisites
Section titled “Prerequisites”- An account on
ops.gitlab.netthat has been added to the appropriate groups (see the note below). kubectlinstalled.glab(the GitLab CLI) installed.
How authentication works
Section titled “How authentication works”When you update your kubeconfig, glab wires
glab cluster agent get-token
in as a kubectl exec credential plugin. When kubectl needs to authenticate, that
plugin creates a short-lived personal access token with the k8s_proxy scope,
valid until the end of the current day, and uses it to talk to the cluster through
the KAS proxy. glab caches the token and reuses it while it’s still valid, so it
only mints a new one once the cached token expires. Either way, these tokens are
managed automatically, so you never handle them directly.
-
Create a personal access token.
Create a personal access token on
ops.gitlab.netwith theapiscope (see How authentication works for why this scope is required). -
Configure
glabforops.gitlab.net.Point
glabatops.gitlab.netusing the token from the previous step. Run the command below and paste the token when prompted, which keeps it out of your shell history:Terminal window glab auth login --hostname ops.gitlab.netIf you’d rather script it, read the token from standard input instead of passing it on the command line. First create
token.txtwithout exposing the token in your shell history: restrict its permissions, then write the token using a text editor orcat > token.txt(paste the token, then pressCtrl+D):Terminal window touch token.txt && chmod 600 token.txtThen authenticate by reading the token from the file, and delete it afterwards:
Terminal window glab auth login --hostname ops.gitlab.net --stdin < token.txtrm token.txt -
Update your kubeconfig.
Find the cluster you want to connect to on the kas-clusters agents page. That page is the source of truth for the available clusters. To get the exact command for a cluster, click the vertical dots menu (
⋮) next to it and select Connect to<cluster>, which shows theglab cluster agent update-kubeconfigcommand (including the agent ID) ready to copy. For example, to configure access to the cluster served by agent70:Terminal window GITLAB_HOST=https://ops.gitlab.net glab cluster agent update-kubeconfig \--repo gitlab-com/gl-infra/platform/runway/kas-clusters \--agent 70 --use-context \--cache-mode keyring-filesystem-fallbackThe
--use-contextflag sets the newly added cluster as your currentkubectlcontext. TheGITLAB_HOST=https://ops.gitlab.netprefix is still required even after Step 2: it pointsupdate-kubeconfigat theops.gitlab.netinstance rather than the defaultgitlab.com. Include thehttps://scheme here (unlike the--hostnameflag in Step 2, which takes a bare hostname).The
--cache-modeflag controls whereglabcaches the token, and its value is written into the exec-plugin config in~/.kube/config. The default,force-keyring, fails on machines without a running keyring (headless Linux, CI, containers), so this example useskeyring-filesystem-fallback, which prefers the OS keyring when available and falls back to filesystem storage when it isn’t. The command copied from the Connect to UI omits this flag and inherits theforce-keyringdefault, so add it yourself. -
Verify connectivity.
List pods across all namespaces:
Terminal window kubectl get pods -AA successful connection returns a listing of pods across the cluster’s namespaces.
Notes and troubleshooting
Section titled “Notes and troubleshooting”- Token expiry: the short-lived
k8s_proxytokens are valid until the end of the current day.glabcaches and reuses a token while it’s valid and mints a fresh one once it expires, so no action is needed from you. - Bootstrap PAT expiry: if
kubectlcommands suddenly start failing with authentication errors, theops.gitlab.netPAT you created in Step 1 may have expired. Once it does,glabcan no longer mint newk8s_proxytokens. Create a new PAT and re-runglab auth login(Step 2) to restore access. - Keyring errors on headless machines: if
kubectlorglabfails with a keyring,dbus, or secret-service style error, your kubeconfig is using theforce-keyringcache mode (the default, and what the Connect to UI generates). Re-runupdate-kubeconfigwith--cache-mode keyring-filesystem-fallback, or edit the--cache-modevalue in~/.kube/config. See theget-tokenoptions for the available modes. - Read-only access: any write operation against a staging or production cluster will be denied. This is expected.
- Need help?: reach out in
#f_runway.