Kubernetes Agent, GitOps Workflows, Cluster Access, Environments, and Deployment Integration: Configuration, Design Choices, and Tradeoffs
Choose deliberately between agent-based access and stored kubeconfig, Flux GitOps and imperative CI deployment, shared and isolated cluster models, and broad versus least-privilege authorization.
Learning objectives
- Compare agent-based access with stored kubeconfig by credential lifetime, distribution, auditability, and blast radius.
- Compare Flux GitOps reconciliation with imperative GitLab CI deployment jobs.
- Choose among shared clusters, per-environment namespaces, and stronger isolation boundaries.
- Design project/group authorization scope that follows least privilege.
- Evaluate maintainability, security, reliability, compatibility, performance, and cost together.
gitops.manifest_projects functionality was removed in
GitLab 17.0; current GitOps guidance uses
Flux plus the GitLab Agent. Therefore the mandatory
chapter path is manifest/identity simulation with no real cluster or
paid feature; any live cluster exercise is optional and disposable.
1. Agent connection versus stored kubeconfig
A stored kubeconfig puts long-lived cluster endpoint and credential material into GitLab CI/CD variables or another secret store. The Agent moves the connection model toward an in-cluster agent with an authenticated KAS channel and dynamically supplied contexts. That reduces direct credential distribution, especially for clusters behind NAT/firewalls, but it does not eliminate authorization design.
| Dimension | Agent-based access | Stored kubeconfig |
|---|---|---|
| Credential distribution | Agent token stays cluster-side; jobs receive generated contexts | Kubeconfig/credential must be delivered to jobs |
| Rotation | Rotate agent tokens/agent installation | Rotate each stored cluster credential |
| Network | Agent initiates outbound channel to KAS | Runner must reach Kubernetes API endpoint |
| Authorization | GitLab ci_access + Kubernetes identity/RBAC | Kubernetes credential/RBAC; GitLab mainly gates variable exposure |
| Auditability | Agent/project/job/environment context can be correlated | Depends heavily on credential and cluster audit design |
| Main risk | Over-broad authorization or powerful agent service account | Secret leakage and credential reuse across jobs |
2. Flux reconciliation versus imperative CI deployment
An imperative CI job says “run these commands against the cluster now.” A GitOps controller says “this repository/OCI source declares desired state; keep the cluster converged to it.” The difference is operational, not cosmetic.
| Question | Imperative CI via Agent | Flux GitOps |
|---|---|---|
| Who initiates change? | Pipeline job pushes API requests | Controller pulls/reconciles desired state |
| Ongoing drift correction | No, unless another pipeline/job handles it | Yes, controller continuously reconciles |
| Production security posture | GitLab docs call this weaker and advise against production deployment use | Current recommended pull-based GitOps path |
| Best fit | Controlled pipeline-driven operations, migrations, read-only checks | Production declarative workloads and drift management |
| Failure evidence | Job logs + Kubernetes API response | Source/controller reconciliation status + cluster state |
3. Shared cluster versus namespace or cluster isolation
A namespace is an administrative and naming boundary, not automatically a strong security boundary. Shared-cluster designs can be efficient, but cluster-scoped resources, controllers, network policy, admission policy, and node/runtime configuration can cross namespace boundaries. For sensitive environments, separate clusters or stronger tenancy controls may be justified.
| Pattern | Benefits | Costs / risks |
|---|---|---|
| One shared cluster, many namespaces | Low platform cost; centralized operations | High shared blast radius; complex multi-tenancy controls |
| Separate namespace per environment | Clearer workload separation; easier quota/RBAC | Still shares cluster-wide control plane/nodes |
| Separate production cluster | Stronger fault/authorization boundary | More operational cost and lifecycle overhead |
| Ephemeral review clusters | Maximum isolation per review | Provisioning time/cost; cleanup complexity |
4. Project authorization breadth is a platform architecture decision
Authorizing an individual project is easier to reason about than granting a whole group. A group authorization also extends to subgroup projects. Current GitLab supports environment filters on Free, which is a useful narrowing mechanism. Avoid granting “all projects” merely for convenience; instance-level authorization exists only on Self-Managed and is administrator-controlled.
ci_access:
projects:
- id: company/payments/deploy
environments: [production]
groups:
- id: company/sandbox
environments: [review/*]
The first line of defense is scope. The second is effective Kubernetes identity/RBAC. Premium/Ultimate impersonation improves that second layer, but even without it a dedicated low-privilege agent service account is safer than cluster-admin.
5. Service-account authority versus impersonation
On the Free basic CI workflow, requests inherit permissions from the
service account used by agentk. If that service account is
cluster-admin, every authorized job potentially inherits dangerous
power. Premium/Ultimate CI job impersonation lets agentk present
groups such as gitlab:ci_job, project IDs, and
environment/tier groups to Kubernetes RBAC, enabling finer
authorization.
6. Protected refs and runners are complementary controls, not substitutes for RBAC
Production access should consider source trust, runner trust,
environment authorization, and cluster RBAC together. GitLab
supports protected_branches_only for agent access on
Self-Managed/Dedicated, but current documentation still carries a
caution that the feature is for testing/not ready for production. Do
not make it the only production boundary. On GitLab.com, use
protected refs, environment filters, trusted runners, and
Kubernetes-side controls appropriate to your tier.
7. Environment integration and GitLab-managed Kubernetes resources
GitLab can associate an environment job with an agent and, in newer workflows, manage environment Kubernetes resources through agent configuration. Treat this as a convenience/control plane, not an excuse to blur ownership. The manifest repository, environment template, agent configuration, and cluster RBAC should have explicit owners and review paths.
deploy_review:
stage: deploy
script:
- echo "deployment action is intentionally synthetic"
environment:
name: review/$CI_COMMIT_REF_SLUG
kubernetes:
agent: company/platform/agent-config:lab-agent
8. Worked decision: a regulated API with review apps and production
Assume a 20-person team needs disposable review environments and a tightly controlled production cluster.
| Concern | Review environments | Production |
|---|---|---|
| Cluster model | Shared non-production cluster, namespace per review | Dedicated production cluster |
| Delivery | CI job or GitOps depending lifecycle | Flux GitOps |
| GitLab authorization | Project + review/* environment filter |
Dedicated deploy project + production environment filter |
| Kubernetes identity | Low-privilege namespace access | Premium/Ultimate CI/user impersonation if interactive access is needed; controller SA least privilege |
| Runner | Disposable/trusted non-prod runner | No direct production push if using Flux; trusted build/signing path only |
| Evidence | Environment name + namespace + SHA | Git commit + manifest revision + image digest + Flux Ready + observed workload |
This design spends complexity where the blast radius is highest. It also keeps review-app convenience from silently becoming production authority.
Knowledge check
Why can the Agent be safer than storing a kubeconfig in CI variables?
It reduces direct distribution of long-lived cluster credentials and uses an authenticated agent/KAS connection, though authorization and runner trust still must be designed.
What is the main operational advantage of Flux over a one-shot kubectl apply job?
Continuous reconciliation and drift correction against declared desired state.
Does a namespace guarantee tenant isolation?
No. It is an important scope boundary but shares cluster-wide resources and infrastructure unless additional controls provide stronger isolation.
What is the risk of a cluster-admin agent service account on Free?
All authorized CI jobs may inherit that broad cluster authority because default agent impersonation uses the agent service account.
Should protected_branches_only be your only production safeguard?
No. Current docs carry deployment-status caveats and it applies only to some offerings. Layer ref/environment/runner trust with Kubernetes RBAC and safer deployment architecture.
9. Summary and next bridge
The architecture decision is now explicit: use the Agent to avoid uncontrolled credential distribution, prefer Flux for production pull-based reconciliation, and make GitLab scope plus Kubernetes RBAC independently least-privilege. Lesson 4 practices diagnosing the failures that occur when one of those layers is broader, stale, or misinterpreted.
Primary sources and version notes
These lessons were finalized against current official GitLab documentation on 2026-08-22. Kubernetes, Flux, agentk, glab, KAS, and cluster security evolve independently, so re-check current GitLab version/tier, supported agent/Kubernetes versions, CLI syntax, and cluster policy before production use.
- GitLab 19.3 release
- Connecting a Kubernetes cluster with GitLab
- Install the GitLab Agent for Kubernetes
- Using GitLab CI/CD with a Kubernetes cluster
- Grant users Kubernetes access
- Using GitOps with a Kubernetes cluster
- Migrate legacy agent GitOps to Flux
- Managing agent instances and tokens
- Kubernetes Agent REST API
- Kubernetes managed resources and environments
- GitLab deprecations and removals
- GitLab token security overview
Keep the academy open
Support free, practical DevOps education.
Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0Send only Ethereum/ERC-20 compatible assets to this
address.