Back to Terraform

ACK and Container Registry: Cluster Activation, Roles and Workload Separation

November 6, 2026 Wasil Zafar 27 min read

Provision Alibaba container infrastructure and stage Kubernetes resources only after the API is ready

Table of Contents

  1. Bootstrap ACK Activation and Required Service Roles
  2. Choose the Supported Cluster and Node-Pool Model
  3. Map Registry, Node and Pod Access Separately
  4. Stage Kubernetes Provider Operations After API Readiness
  5. Verify One Workload and Audit Cloud Resources

Bootstrap ACK Activation and Required Service Roles

ACK is a service before it is a resource. No cluster configuration can succeed in an account that has never opened Container Service, and no cluster object records that the opening happened. Activation is therefore an account-level step with its own evidence, not a line inside a workload apply.

Activation arrives as a data source, which surprises people. In the pinned provider the call is alicloud_ack_service, configured with enable and a billing type, and it performs the activation when the configuration is read. A data source that changes the account is a real exception to the usual read-only expectation, so treat the file that holds it as privileged.

A plan can activate the account and report nothing. Because the read returns rather than creating an addressable object, the apply summary can show zero resources added while the account has just been opened. Do not read that as a no-op, and do not put the call in a root that runs on every commit.

Roles are where a green plan still produces a broken cluster. A managed cluster assumes a RAM role for each component it installs, and those roles trust the Container Service principal rather than a person. Create the cluster without them and the control plane may come up while logging, storage or networking reports a component that cannot assume its role.

Table 1 maps the roles a first cluster is likely to need and what each one reaches.

Service roleAssumed byReachesRequired when
AliyunCSDefaultRolecluster management operationsECS, VPC, SLB, ROS, ESSthe cluster is created
AliyunCSManagedKubernetesRolemanaged cluster defaultECS, VPC, SLB, ACRa managed cluster runs
AliyunCSManagedNetworkRolenetwork componentECS, VPCTerway is installed
AliyunCSManagedCsiRolestorage componentECS, NAS, OSSCSI provisioning is used
AliyunCSManagedAcrRolecredential-free pullACRpasswordless pulls are used
AliyunCSManagedAutoScalerRoleautoscalerESS, ECSa pool sets scaling bounds
AliyunCSManagedNlcRolenode lifecycle controllerECS, node poolsthe pool is a managed pool
AliyunCSManagedLogRolelog componentSLSlog collection is enabled

Only create the roles the cluster will install. A role whose component is disabled is standing permission with no owner and no review path. The full set spans logging, monitoring, storage, audit, autoscaling and cost analysis, and a lab cluster needs a small subset of it.

The trust policy is identical across the whole set. Every role trusts the same service principal, so the name and the attached system policy are the only things separating a log reader from cluster administration. Review the policy, not the description.

The published sample still uses deprecated arguments. The current ACK example writes name and document, which the earlier provider part already flagged as replaced. Use the current field names in new code, because a deprecation that survives one major release tends to be enforced at the next.

Privilege belongs outside the application root. Creating roles needs RAM write actions that no deployment pipeline should hold, and a role that outlives a cluster is not the workload's to delete. Put activation and role creation in a platform bootstrap root, and let the cluster root read role names as inputs.

force is a destroy flag with a live-cluster consequence. The sample sets it so a role with attachments can be removed, which is convenient in a sandbox and risky against a running cluster. Prefer detaching deliberately and retaining the role when a component still depends on it.

Figure 1 follows the bootstrap order and keeps the three failure branches visible: no activation, a missing role, and a policy that is wider than the component's job.

Bootstrap ACK Activation and Required Service Roles
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    ACCT["Alibaba Cloud account
billing and ownership"] --> ACT["Activate ACK
read performs the call"] ACT --> ROLES["Create the component roles
trust cs.aliyuncs.com"] ROLES --> CL["Managed cluster
standard or Pro tier"] CL --> NP["Node pools
worker role attached"] NP --> ADD["Add-ons assume their roles"] ADD --> RES["ECS, VPC, SLB, ACR, SLS"] ACT -.->|"skipped"| F1["Cluster create rejected
service not activated"] ROLES -.->|"role absent"| F2["Add-on degraded
cannot assume the role"] ADD -.->|"policy wider than the job"| F3["Component can exceed
its own boundary"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class ACCT,ROLES primary; class ACT,CL,NP secondary; class ADD,RES ok; class F1,F2,F3 danger;

Figure 2 shows the same bootstrap as three ownership roots, with the privilege boundary drawn where it actually sits.

Activation and role creation sit in a bootstrap root outside the cluster and workload roots Three panels. The bootstrap root owns ACK activation, component role creation and the role names it publishes. The cluster root owns the VPC attachment, the managed control plane, node pools and add-ons, and consumes those role names. The workload root owns the Kubernetes provider, the namespace and the deployment, and holds no RAM write permission. Dashed connectors carry role names and the API endpoint across the boundaries. Three roots, one privilege boundary Activation runs once per account. The cluster root only consumes what it produced. Bootstrap root account-level, runs once Activate ACK read performs the call Create component roles trust cs.aliyuncs.com Publish role names outputs, never credentials holds RAM write actions Cluster root Alibaba Cloud API only VPC and VSwitch inputs from the network root Managed cluster network model fixed here Node pools and add-ons each assumes a role Workload root Kubernetes objects only Kubernetes provider host and credential from outputs Namespace and account the workload subject No RAM writes cannot create or delete roles A role that outlives the cluster is not the workload's object to delete. The workload pipeline receives a host and a credential. It never receives permission to create RAM roles.

Choose the Supported Cluster and Node-Pool Model

Spec is a support and quota decision, not a size dial. The cluster specification selects the basic managed tier or one of the Pro tiers, which differ in control-plane capacity, audit and SLA rather than in node count. Choose from the API throughput and the audit evidence you need, then size the data plane separately.

Some cluster properties are replacement decisions wearing a resource address. A service CIDR, a pod VSwitch list, the security-group mode and the kube-proxy mode are all settled when the cluster is built. Reading the schema before the first apply is cheaper than discovering the constraint during a change window.

Table 2 lists the fields that turn an edit into a rebuild.

PropertyAfter creationWhat a change costs
service_cidrreplacement onlya new cluster and re-addressed Services
pod_vswitch_idscreate onlyTerway keeps the original pod address plan
is_enterprise_security_groupreplacement onlya new cluster
proxy_modereplacement onlya new cluster
enable_rrsacreate only, cannot be disableda new cluster to gain pod identity
vswitch_idsupdatablethe control plane restarts
versionraise onlyno downgrade, and auto-upgrade owns the field
addons blockcreate onlylater add-ons need the separate add-on resource

The network model decides where a pod's address comes from. Terway takes pod addresses from VPC VSwitches you pass in, so pod traffic is routable and security groups apply at the pod's ENI. Flannel draws from a pod CIDR and moves traffic over an overlay, which needs no pod VSwitch and costs an extra hop.

Address budget follows the CNI, and it is easy to get wrong. A Terway pod consumes a VPC address, and a node reserves ENIs and secondary addresses before those pods exist, so the pod VSwitches must be sized from pods per node times node count plus surge. Flannel converts the same pressure into the per-node CIDR mask instead.

Table 3 compares the two models on what they consume and what they need from you.

ModelPod addressRoutable from the VPCInputs to supplyFails when
TerwayVPC address on an ENIyes, subject to security groupspod VSwitches, one per zonepod VSwitches run out of addresses
Flanneladdress from the pod CIDRno, overlay and NATone pod CIDR, node masknode mask caps pods per node

Create the cluster with zero workers, then add node pools. The provider's own guidance points this way, and the reason is lifecycle: a pool can be scaled, replaced, tainted and drained without touching the control plane. A worker count baked into the cluster resource has no separate lifecycle to operate.

Node pools carry the worker identity. The pool's role field decides which RAM role the kubelets and node agents assume; leave it empty and the cluster's default worker role applies. That role is node-wide, which is the reason the next section keeps application grants away from it.

Taints and labels are the scheduling contract. A system pool can carry a taint so application pods only land on pools that were sized for them, and scaling bounds are set per pool. The autoscaler role must exist before a pool asks for elastic capacity.

Version moves in one direction. The cluster version can be raised but not lowered, and an auto-upgrade policy takes ownership of the field, so a pinned version and an automatic channel are two different decisions. Node pools follow through their own upgrade policy, and a control-plane-only upgrade leaves a skew you have to record.

Region and zone are capacity questions before they are latency questions. Worker-capable instance types differ by zone, and a list of types is tried in order at purchase time. Query the types for the zone you actually chose, and keep a second type in the list for the day the first is sold out.

Figure 3 walks the model choice from the network root to a bounded node pool, with the three failures that only appear at capacity time.

Choose the Supported Cluster and Node-Pool Model
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    NET["VPC, VSwitches and zones
from the network root"] --> CNI{"Do pods need
VPC addresses?"} CNI -->|"yes"| TER["Terway
pod VSwitches per zone"] CNI -->|"no"| FL["Flannel
pod CIDR and node mask"] TER --> SPEC["Cluster spec
basic or Pro tier"] FL --> SPEC SPEC --> CP["Cluster with zero workers"] CP --> POOL["Node pool
types, zones, taints"] POOL --> Q{"Autoscaling?"} Q -->|"yes"| AS["Scaling bounds plus
autoscaler role"] Q -->|"no"| FIX["Fixed desired size"] AS --> OK["Capacity contract recorded"] FIX --> OK TER -.->|"addresses exhausted"| X1["Pods Pending
no VPC address"] POOL -.->|"type sold out in zone"| X2["Pool stalls or fails"] SPEC -.->|"service CIDR edited later"| X3["Replacement, not a change"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class NET,POOL primary; class CNI,Q warn; class TER,FL,CP,AS,FIX secondary; class OK ok; class X1,X2,X3 danger;

Map Registry, Node and Pod Access Separately

The registry outlives the cluster. Images are pushed many times a day while a cluster changes on a different schedule and may be rebuilt without losing a single artifact. Give the registry instance and its repositories their own root, so a cluster rebuild never becomes a registry migration.

A build is not a pull. CI pushes a tag and records the digest with a build identity that may write to one repository, and the cluster only ever needs to read. Keeping push and pull apart is what lets you revoke a compromised builder without breaking a running deployment.

Registry tier and network are create-time choices. The instance type cannot be changed after creation and the subscription is prepaid, so a move from one tier to another is a new instance and a migration. Decide from scan, replication and VPC-endpoint needs before the first push, not after the first failed pull.

Three access paths, three subjects. Control-plane components assume service roles, the node agent uses the worker RAM role, and an application pod uses a role federated to its service account. Treating those as one identity is how application permissions end up on every node in the cluster.

Table 4 keeps the three grants apart, because they are revoked in three different places.

PathSubjectGrantLifetimeFailure symptom
image pullworker role or managed ACR rolepull on one repositorytemporary token, refreshedimage pull error with no application log
pod cloud APIrole federated to one service accountnamed actions on one resourceSTS session, minutes to hoursaccess denied from inside a running pod
cluster componentACK service rolea system policy per componentsession per calladd-on degraded, cluster healthy

Passwordless pull still uses a Secret. The credential-free add-on asks the registry for a temporary token, writes it into a Secret, and attaches that Secret to the service accounts it watches in configured namespaces. Manifests stop carrying an image pull secret, but a pod in an unwatched namespace still gets nothing.

The helper and a manual pull secret do not coexist. When a workload sets its own pull secret while the add-on also injects one, the pull can fail; remove the manual field before debugging the registry. Personal Edition instances created after early September 2024 are outside the add-on's support and need a real secret instead.

Reachability is a separate contract from permission. A pull can fail with a valid token because the registry has no VPC endpoint in the cluster's VPC, or because the private name does not resolve. Same-region access through the registry's own VPC access control is the intended path; a peering connection needs routes on both sides plus a private name.

A public endpoint is an allowlist decision. If the internet endpoint stays on, enable the endpoint ACL and record the permitted CIDRs as resources so the allowed networks are reviewable. Leaving it open makes the token the only boundary in front of the registry.

RRSA turns a service account into a RAM principal. The cluster publishes an OIDC issuer, RAM holds a provider named for the cluster, and one role trusts one subject string. The pod exchanges its projected token for an STS credential, so no access key is written into a Secret.

The trust policy is a triple. Issuer, audience and subject must all match, and the audience is the STS endpoint rather than your application. A typo in the subject, which names the namespace and service account, fails the exchange with a message that rarely mentions the subject.

Enabling RRSA is a one-way door. The cluster flag must be set at creation and cannot be turned off, because the provider and the issuer become part of the cluster's identity. A cluster built without it needs to be replaced, not edited, when pod identity becomes a requirement.

The webhook removes the YAML, not the trust. With the pod identity add-on installed, a namespace label enables injection and a service account annotation names the role. The pod then receives the role ARN, the provider ARN and the token path, while the role and its conditions remain in RAM.

Figure 4 draws the three paths as three lanes, so a pull failure and a permission failure stop looking like the same incident.

Registry, node and pod access as three separate paths The build lane shows a CI identity pushing an image and recording its digest in the registry. The node lane shows the kubelet using the credential helper and the worker RAM role to write a short-lived pull Secret, then pulling by digest. The pod lane shows a service account projecting an OIDC token that STS exchanges for a role session used against one cloud API. A crimson footer warns that the worker role is reachable from any pod on the node. Three paths, three subjects A registry grant, a node role and a pod role are not interchangeable. Build and registry push once, pull many times CI build identity push on one repository Registry instance repository, digest, scans Digest recorded the deployment names it Node one role for every pod kubelet and helper worker RAM role Temporary pull Secret refreshed, per namespace Image pulled by digest, not by tag Pod one role for one subject Service account namespace plus name Projected OIDC token STS exchanges it for a session One cloud API call scoped by the role policy pull The worker role is node-wide: any pod that reaches the instance metadata service inherits it. Pull permission is not API permission. Grant them to different subjects and revoke them separately.

Stage Kubernetes Provider Operations After API Readiness

The Kubernetes provider connects while the plan is being built. Provider configuration is evaluated before the dependency graph is walked, so a root that creates the cluster and manages objects in the same state has no endpoint to reach on its first run. No dependency edge can make a client wait for a server that the same run is supposed to create.

Split the root at the API, not at the resource type. One root owns the network attachment, the cluster, the node pools, the add-ons and the role inputs. A second owns the provider block, the namespace, the service account, the workload and the service, and reads the endpoint from published outputs.

Three versions define this boundary. Terraform 1.17.1, aliyun/alicloud 2.2.0 and hashicorp/kubernetes 3.5.0 are the releases this part was written against. Treat a provider upgrade as a change to the hand-off rather than a patch.

Cluster status is not API readiness. The cluster resource waits for a running status, and the provider allows ninety minutes for that create. A running control plane still says nothing about whether your runner can reach the endpoint or whether the node CNI has finished.

Read the endpoint, then probe it with the deploy identity. Fetch the host and certificate from the cluster credential data source, and confirm the API answers with the same identity the deploy will use. Checking with an administrator credential proves reachability and hides an authorization gap.

Two authorizations gate every deploy. RAM decides whether the pipeline may fetch a cluster credential at all, and Kubernetes RBAC decides what the resulting user may create. A pipeline can pass the first and fail the second with an error about namespaces rather than credentials.

A kubeconfig in a pipeline is a secret in a pipeline. A rendered file carries client credentials that outlive the job and often the workspace, so prefer a credential process that mints a token for each run. The provider reads it at plan time and again at apply time, which is also when an expired token shows up.

A private endpoint moves the runner. With the public API load balancer disabled, the endpoint resolves only inside the VPC or a connected network, so the runner needs a private path to it. A laptop plan then fails before it can show a diff, and that failure is the design working.

Add-on CRDs are a second gate. An ingress controller or a service mesh installs custom resource definitions, and a manifest that uses those kinds needs the schema to exist before the plan can read it. Gate the workload root on the add-on, not on the cluster alone.

Hand the gate to the pipeline. Apply infrastructure, publish the host and issuer, probe readiness, then plan the workload root. Terraform orders resources inside one state; across a hand-off only the pipeline can hold the order.

Figure 5 contrasts one root that cannot configure its provider with two roots joined by a readiness step.

A single root fails at provider configuration while two roots pass through a readiness gate The left panel is one root: plan starts, the Kubernetes provider reads its configuration, the cluster endpoint does not exist yet, and the run aborts before a diff. The right panel applies the cluster root, publishes the host and issuer, probes the API and node readiness, then plans the workload root. A footer states that the hand-off is a pipeline step, not a Terraform dependency. The client starts before the server exists Provider configuration runs during plan, so it cannot depend on a cluster from the same run. One root cluster and objects in one state terraform plan provider reads its configuration No endpoint to reach the cluster does not exist yet Run aborts no diff, and a message about configuration depends_on cannot help the client is not a graph node Two roots a pipeline step between them Apply the cluster root publishes host, CA and issuer Readiness gate API answers, nodes Ready, add-ons up Plan the workload root namespace, account, deployment Objects reconciled one digest, one identity The hand-off is a pipeline step, not a Terraform dependency.

Verify One Workload and Audit Cloud Resources

One workload proves the whole path. A namespace, a deployment, a ClusterIP service and one service account cover scheduling, image pull, DNS and identity. Ingress, autoscaling and a mesh add variables before the straight line is known to work.

Break the two paths on purpose. Remove the registry permission and watch the image fail, restore it, then remove the role's policy and watch one API call fail. A single failing test says nothing about which boundary broke.

Scale to zero before you delete. Scaling the deployment down first proves the service holds no load balancer of its own; only a service of type LoadBalancer creates one, and that object is billed and separately owned. Discovering it after the namespace is gone is the usual surprise.

Teardown follows the graph you created. Workload objects first, then load balancers and volumes created by controllers, then node pools, then the cluster, then the registry, then the network pieces. The reverse order strands cloud objects that no Terraform address owns.

The cluster resource deletes more than the cluster. NAT gateways, SNAT rules, load balancers and the RAM roles created with the cluster are removed on destroy unless they are retained. That is convenient for a lab and dangerous when a shared registry or ingress sits behind one of those objects. A retain list also has to be applied in an earlier run, because adding it during the teardown changes nothing.

Delete options decide what survives, and the defaults are not uniform. Load balancers created by the ingress controller are deleted by default, while the application load balancer and the log projects are retained. Set the mode per resource type instead of assuming one behaviour.

A clean destroy is not an audit. Check load balancers, elastic addresses, disks, network interfaces, file storage and log projects after the apply that destroys. A zero exit code with a stranded disk is the most common result of a hurried teardown.

Lab

Verify One Workload and Audit Cloud Resources

Execution status: design-only. This is a lab plan for Terraform 1.17.1, aliyun/alicloud 2.2.0 and hashicorp/kubernetes 3.5.0 against a disposable account. No command output, cluster ID or registry address is recorded here, and none of these steps was run.

Prerequisites. A VPC with two node VSwitches and two pod VSwitches from the network root, permission to create RAM roles, one registry instance with a repository you can push to, and a runner that can reach the endpoint you choose. Use an image you built yourself; nothing here depends on a public image.

BoundaryOwner rootPass condition
activation and rolesbootstrapthe cluster creates without a missing-role message
cluster networkclusternodes register and pods receive addresses
image pullclusterthe pod reaches Running with no pull error
pod identityworkloadone permitted call succeeds, one is denied
teardownall threeno load balancer, disk or address survives
  1. Apply the bootstrap root and confirm the role set matches the components you intend to install, not the full published list.
  2. Apply the cluster root with the chosen network model, zero workers, RRSA enabled, and the endpoint exposure you can actually reach. Expect a long create and a running status at the end.
  3. Add one node pool with a taint for applications and a bounded desired size, then confirm every node reaches Ready.
  4. Read the API host, the certificate and the issuer, and confirm RAM lists an OIDC provider for this cluster that trusts that issuer.
  5. Apply the workload root as a deploy identity that holds namespace rights only. Confirm a plan against a namespace the identity does not own is refused.
  6. Push one image with the build identity, record the digest, and reference the digest rather than the tag.
  7. Deploy the workload with the annotated service account, confirm the pod is Running, and read the image identity from the running container rather than from the manifest.
  8. Exec into the pod and call one API action the role allows, then one it does not. Record both messages.
  9. Create a service of type LoadBalancer in a branch and watch the load balancer appear, then delete the service and wait for the cloud object to leave.
  10. Destroy in order: workload root, node pools, cluster, registry content, then the network inputs. After each stage, list the resources that stage should have removed.

Expected observation. The first workload reaches Running without a pull secret, one API call succeeds and one is denied, and the destroy leaves no billed object behind. Each stage removes only what its own root created.

Failure checks. The lab fails if the pod can call an API its role does not grant, if a pull succeeds only after a manual secret is added, if a load balancer or elastic address survives the workload destroy, if the cluster destroy removes a role you meant to keep, or if the registry loses a digest that a rollback still needs.

Cleanup. Delete the service before the namespace, confirm the load balancer and its address are gone, release the registry repository, then remove the cluster and the node pools. Keep the bootstrap root, because the roles are reusable and recreating them is the slowest part of a rebuild.

Evidence to keep. The activation record, the role list with trust principals, the endpoint and issuer outputs, the approved digest, one permitted and one denied API result, the pull failure without permission, and the post-destroy inventory of each resource type.

Next in the Series

In Function Compute and Events: Application Artifacts, APIs and RAM Permissions, we'll explore Wire serverless code and cloud events using release-specific resources and explicit identities.