A deploy to a Kubernetes cluster from GitLab: agent or kubeconfig?
AdvancedScenarioGitLab CI
Answer
Situation read → Cluster connectivity choice.
What I'd do →
- Prefer the GitLab agent for Kubernetes: the in-cluster agent opens an outbound tunnel, so no cluster API exposure to runners.
- Grant CI access with
ci_accessin the agent config, and bind to namespaced RBAC. - In jobs:
kubectl config use-context group/project:agent-namethenkubectl apply. - Or use pull-based GitOps with Flux and the agent's Flux integration.
Why → Outbound-only connections are safer than kubeconfig secrets in CI.
Interview tip → Push CI deploy vs pull GitOps is a standard trade-off question.
More on GitLab CI
How does GitLab CI/CD work at a high level?BeginnerWhat is a GitLab Runner and what executors exist?IntermediateWhat are the types of runners (shared, group, project) and tags?IntermediateHow do `rules:` work and how do they replace `only/except`?IntermediateWhat are workflow rules and how do they prevent duplicate pipelines?AdvancedHow do artifacts and cache differ in GitLab CI?Intermediate