Courseiva
CKSChapter 2 of 15Objective 1.2

Cluster Setup: Secure Configuration and Best Practices

How do you stop an attacker from walking into your Kubernetes cluster the moment it goes live? Before you add a single application or database, you must configure the cluster itself to be secure, otherwise every security measure you add later is built on a cracked foundation. This chapter covers the essential, non-negotiable steps to harden a Kubernetes cluster from the ground up, which is exactly what the CKS exam objective 1.2 expects you to master.

12 min read
Intermediate
Updated Jul 23, 2026
Reviewed by Johnson Ajibi· Senior Network & Security Engineer · MSc IT Security

A simple way to picture Cluster Setup: Secure Configuration and Best Practices

The New House Security Setup Analogy

You've just bought a new house. The builders finished yesterday, and the keys are in your hand. Before you move a single box in, what is the first thing you do? You don't just lock the front door and call it done. You walk around the entire property. You check every window latch. You change the locks because you don't know who has a copy of the builder's keys. You set the alarm system. You decide who gets a key and who doesn't. This is not about decorating the living room; it is about securing the shell that protects everything inside.

Setting up a Kubernetes cluster is exactly the same. 'Cluster Setup' is the moment you take that brand-new, empty cluster and lock it down before your applications move in. You are not configuring the app yet. You are securing the control plane (the master bedroom lock), the worker nodes (the downstairs windows), the network (the fence between your house and the neighbour's), and the authentication (deciding which friends get a key versus which ones need to ring the doorbell). If you skip this step, an intruder can walk right in when you deploy your first application. The CKS exam tests whether you know exactly which locks to change, which alarms to set, and which spare keys to hide before you invite any data inside.

How It Actually Works

Let's break down what a Kubernetes cluster actually is. A Kubernetes cluster is a group of computers (servers) that work together to run your applications. Think of it as a team of robots: one robot is the boss (the control plane), and the others are the workers (the worker nodes). The boss makes all the decisions: it decides what should run, where it should run, and when to restart something if it crashes. The workers just follow orders. This sounds simple, but securing the relationship between the boss and the workers is where the complexity begins.

Every component in a Kubernetes cluster communicates over a network. That means data is being sent between the boss and the workers, between the workers themselves, and between the outside world and the applications running inside. If you do not secure these communication channels, an attacker can intercept the orders the boss sends to the workers and tell the workers to run a malicious application instead.

To understand the secure setup, you need to know the key components you will be securing. These are:

The API Server: This is the front door of the boss. Every single command to the cluster goes through this server. If you lock this door properly, you control who can do what. If you leave it unlocked, anyone can take over.

etcd: This is the brain of the cluster where all configuration data lives. It stores passwords, secrets, and the entire state of the cluster. If an attacker reads etcd, they have the keys to the kingdom.

Kubelet: This is a small agent that runs on each worker node. The kubelet receives orders from the boss and carries them out. If you do not secure the kubelet, an attacker could fool a worker into running their code.

Kubeconfig files: These are the 'key files' used to authenticate to the API Server. If someone steals your kubeconfig file, they can log in as you.

Why does this matter? In older IT systems, you could rely on a physical network firewall to keep bad things out. Everything inside the network was assumed to be 'safe'. This is called a 'castle-and-moat' model. But Kubernetes is designed for cloud-native environments where the network is not a single protected box; it is a maze of connections across different servers, often in different data centres. The 'moat' does not exist. Therefore, you must secure every component independently. This is called 'defence in depth' — you do not rely on one lock; you have three locks in a row.

The CKS exam specifically tests your ability to apply three core security practices during cluster setup: authentication and authorisation (who are you and what are you allowed to do?), TLS bootstrapping (setting up encrypted communication automatically), and node metadata protection (preventing worker nodes from leaking cloud provider secrets). You must also know how to disable insecure port access, how to restrict access to the kubelet API, and how to set up role-based access control (RBAC) from day one.

A common trap beginners fall into is leaving the 'insecure port' on the API Server open. By default, the API Server used to listen on an insecure port (port 8080) that did not require any authentication. Anyone who could reach that port could administer the cluster. The secure setup practice is to disable that port completely. You must also protect the etcd data store with encryption at rest, because if someone gains access to the disk where etcd is stored, they should not be able to read your secrets.

To summarise the technical process, secure cluster setup involves:

Disabling anonymous authentication and insecure ports on the API Server.

Configuring RBAC so that users and services have the minimum permissions they need (principle of least privilege).

Enabling TLS for all communication paths between components.

Setting up kubelet authentication and authorisation so the kubelet only accepts commands from the API Server, not from anyone else on the network.

Encrypting secrets at rest in etcd.

Each of these steps adds a layer of protection. If you skip one, the chain of security breaks. The CKS exam will ask you to identify which step is missing in a given scenario, or to fix a broken configuration YAML file.

Flow of a request from the internet through the API Server, where it must pass authentication and RBAC checks before reaching etcd or the kubelet on a worker node.

Walk-Through

1

Disable the Insecure API Server Port

Edit the API Server manifest at /etc/kubernetes/manifests/kube-apiserver.yaml. Remove the line '--insecure-port=8080' or change it to '--insecure-port=0'. This prevents anyone from accessing the API Server without authentication. The static pod will automatically restart with the change.

2

Disable Anonymous Authentication

Add the flag '--anonymous-auth=false' to the same API Server manifest file. This ensures that any request without valid credentials is rejected, closing a major hole where unauthenticated users could read cluster state.

3

Enable RBAC Authorization

Set the flag '--authorization-mode=Node,RBAC' in the API Server manifest. The 'Node' module handles authorisation for kubelet requests, and 'RBAC' handles everything else. Without this mode, the cluster remains in 'AlwaysAllow' mode, meaning anyone can do anything once authenticated.

4

Encrypt Secrets at Rest in etcd

Create a YAML file (e.g., /etc/kubernetes/enc/enc.yaml) that specifies an encryption provider (such as 'aescbc') and a key. Then add the flag '--encryption-provider-config=/etc/kubernetes/enc/enc.yaml' to the API Server manifest. This encrypts all secrets stored in etcd, protecting them if the etcd data files are stolen.

5

Secure the Kubelet Configuration

Edit the kubelet configuration file (typically /var/lib/kubelet/config.yaml). Set 'authentication.anonymous.enabled' to 'false' and set 'authentication.webhook.enabled' to 'true'. This forces the kubelet to require a valid bearer token from the API Server before it accepts any command to create or modify pods on the node.

6

Block Access to Cloud Instance Metadata

On each node, add an iptables rule or network policy that blocks outbound traffic to the cloud metadata IP address (169.254.169.254 for most providers). This prevents a pod that has been compromised from querying the metadata service to obtain cloud IAM roles or other secrets.

What This Looks Like on the Job

You are the new security engineer at a mid-sized e-commerce company. The company is migrating its online store from a traditional set of servers to a Kubernetes cluster running on a cloud provider. The team has provisioned a brand-new cluster using a managed Kubernetes service (like Amazon EKS or Azure Kubernetes Service). It is your job to secure it before the first application goes live.

You log into the cloud provider's console and download the kubeconfig file for the cluster. Using kubectl (the command-line tool for interacting with clusters), you first check the current configuration. You run the command 'kubectl config view' and notice that anonymous authentication is still enabled. This means anyone who can reach the API Server's IP address — even people on the internet if the cluster is exposed — can send commands without logging in. That is your first critical fix.

Your next step is to examine the API Server's configuration file (usually found at /etc/kubernetes/manifests/kube-apiserver.yaml on the control plane node). You open the file and find the flag '--insecure-port=8080' is still present. This is a massive security hole. You immediately remove that line to disable the insecure port. Then you ensure the '--anonymous-auth=false' flag is set.

Now you move on to securing the etcd database. You check whether etcd has TLS enabled. You find that it does, but the encryption of secrets at rest is not turned on. This means if an attacker gets a copy of the etcd database files, they can read all passwords, API keys, and database credentials stored in the cluster. You enable encryption by creating an EncryptionConfiguration object and adding the '--encryption-provider-config' flag to the API Server manifest.

Next, you tackle the kubelet configuration. You connect to a worker node via SSH and inspect the kubelet configuration file. You see that the kubelet is configured with '--anonymous-auth=true'. This is dangerous because it means any process on the worker node (or any attacker who gains access to the node) can query the kubelet for information about running pods and can even execute commands inside containers. You change the flag to 'false' and add '--authentication-token-webhook=true' so the kubelet only accepts authenticated requests from the API Server.

The final step in your setup is configuring RBAC. You create a service account for the deployment pipeline that needs to push updates. You grant this service account only the permissions to create pods and deployments in a specific namespace. You explicitly deny it access to secrets and to the node-level API. You also create a read-only role for the monitoring team so they can view logs but cannot change anything.

After completing these steps, you run a security scan. The scan confirms that the insecure port is closed, anonymous access is disabled, kubelet authentication is enforced, etcd is encrypted, and RBAC restricts every action. The cluster is now ready for applications. Without these steps, the first application you deploy could be compromised before it even starts serving customers.

How CKS Actually Tests This

The CKS exam is a performance-based test, meaning you actually have to fix configurations in a live cluster, not just answer multiple-choice questions. For objective 1.2 (Cluster Setup: Secure Configuration and Best Practices), you will be given a scenario where a cluster is already running but is insecure. You must identify the vulnerabilities and apply the correct fix using command-line tools and configuration file edits.

The exam loves testing the following specific concepts:

Disabling the insecure port: They will leave the '--insecure-port=8080' flag in the API Server manifest. You must remove it or set it to 0. They may also ask you to check if the flag is present using 'ps aux | grep kube-apiserver'.

Configuring anonymous authentication: They will set '--anonymous-auth=true' or omit it entirely. You must explicitly set it to 'false'.

Enabling RBAC: They might set '--authorization-mode=AlwaysAllow'. This allows everyone to do everything. You must change it to 'RBAC'. They love to test that the order of the authorization modules matters; the correct order is 'Node,RBAC' for most clusters.

Securing etcd: They will either not have TLS configured for etcd communication, or they will not have encryption at rest enabled. You must create the EncryptionConfiguration YAML file and reference it in the API Server manifest.

Kubelet authentication: They will configure the kubelet to allow anonymous access. You must set '--anonymous-auth=false' and '--authentication-token-webhook=true' in the kubelet configuration file (usually /var/lib/kubelet/config.yaml).

Protecting cloud metadata: If the cluster is running on a cloud provider (like AWS, GCP, or Azure), they will test whether you can block pods from accessing the cloud instance metadata endpoint (e.g., 169.254.169.254). This prevents a compromised pod from stealing cloud IAM credentials.

The traps in the exam are subtle. For example, they may ask you to enable encryption at rest, and you create the configuration correctly, but you forget to restart the API Server after editing the manifest. The change will not take effect, and you will lose points. Another common trap: they will set up a 'kubeconfig' file with a user that has 'system:masters' privileges, which bypasses RBAC entirely. You must recognise that and remove or modify that user.

You should memorise the following file paths and flags because you will edit them during the exam:

API Server manifest: /etc/kubernetes/manifests/kube-apiserver.yaml

Kubelet config: /var/lib/kubelet/config.yaml (or sometimes /etc/kubernetes/kubelet.conf)

etcd manifest: /etc/kubernetes/manifests/etcd.yaml

Encryption configuration: you will create it as /etc/kubernetes/enc/enc.yaml and then reference it.

The exam also expects you to know how to verify your fix. Use 'kubectl get pods -n kube-system' to check if the API Server pod restarted successfully. Use 'kubectl auth can-i' to test RBAC permissions. Use 'kubectl describe pod' to check events that indicate configuration errors.

Finally, the exam will occasionally present a scenario where the cluster is using a managed service and you cannot modify the control plane directly. In that case, you must use cloud-provider-specific tools (like AWS CLI or Azure CLI) to configure security settings. But most of the CKS exam uses a self-hosted cluster (kubeadm) where you directly edit files on the control plane node.

Key Takeaways

The insecure port (8080) on the API Server must be disabled by removing the '--insecure-port' flag or setting it to 0, because it allows unauthenticated access to the cluster.

Anonymous authentication on the API Server must be explicitly set to 'false' to prevent unknown users from sending commands to your cluster.

RBAC (Role-Based Access Control) must be enabled by setting '--authorization-mode=Node,RBAC' on the API Server to enforce who can perform which actions.

Secrets stored in etcd must be encrypted at rest by creating an EncryptionConfiguration; this is never enabled by default.

The kubelet on each worker node must disable anonymous access and require authentication from the API Server to prevent node-level attacks.

Cloud instance metadata endpoints must be blocked for pods to prevent attackers from stealing cloud IAM credentials if a pod is compromised.

The 'system:masters' group bypasses RBAC and should be avoided for regular administration; use custom roles and bindings instead.

Easy to Mix Up

These come up on the exam all the time. Here's how to tell them apart.

Insecure Port (8080)

Does not require any authentication to send commands

Should be disabled in production and during CKS exam

Used only for local testing or debugging

Secure Port (6443)

Requires TLS certificates and authentication tokens

Is the default port for all secure Kubernetes API traffic

Must be the only port enabled on the API Server

RBAC (Role-Based Access Control)

Relies on roles and role bindings defined per namespace or cluster-wide

Easier to audit and manage at scale

Is the recommended and tested mode for CKS

ABAC (Attribute-Based Access Control)

Relies on policies attached directly to users or groups

Harder to manage and troubleshoot for large teams

Legacy mode; less commonly tested on CKS

etcd Encryption at Rest (aescbc)

Protects data when the etcd database files are on disk

Must be explicitly configured via EncryptionConfiguration

Does not encrypt data while it is being read by the API Server

etcd Encryption in Transit (TLS)

Protects data while it is being sent between etcd and the API Server

Is typically enabled by default in kubeadm setups

Does not protect the data if the disk is stolen

Anonymous Authentication Enabled

Allows unauthenticated users to read cluster state

Is the default in some older Kubernetes versions

Creates a serious security hole for the cluster

Anonymous Authentication Disabled

Rejects all requests without valid credentials

Is a mandatory step for secure cluster setup

Must be set with the flag '--anonymous-auth=false'

Watch Out for These

Mistake

If I use a managed Kubernetes service from a cloud provider (like AKS or EKS), the cluster is already fully secure and I do not need to do anything.

Correct

Managed services secure the control plane components, but the worker nodes, network policies, RBAC, and kubelet configuration are your responsibility. Managed does not mean automatically hardened.

Cloud providers call it 'shared responsibility'. They secure the hypervisor and the managed control plane, but they give you a default configuration that is often permissive for ease of use. Beginners assume 'managed' means 'managed security', but it only means 'managed operations'.

Mistake

Disabling the insecure port (8080) is optional as long as I have a firewall blocking external traffic.

Correct

The insecure port must be disabled at the API Server level, not just blocked by a firewall. An attacker who gets a foothold inside the network (e.g., through a compromised application) can access port 8080 from within the cluster and bypass all authentication.

This misconception comes from traditional network security thinking where you only block the outside. Kubernetes security is about assuming the internal network is already compromised, so you lock down every component individually.

Mistake

If I enable RBAC, I do not need to worry about the kubelet authentication. The kubelet will just trust the API Server.

Correct

RBAC controls access to the API Server, but the kubelet has its own separate authentication system. By default, the kubelet allows anonymous access. You must explicitly configure the kubelet to authenticate requests from the API Server using TLS certificates.

Beginners assume that enabling 'authorization mode: RBAC' on the API Server magically secures all other components. They do not realise that the kubelet runs independently and has its own insecure defaults.

Mistake

Encrypting secrets at rest in etcd is automatically enabled in Kubernetes 1.13 and later.

Correct

Encryption at rest must be manually configured by creating an EncryptionConfiguration resource and passing it to the API Server. It is never enabled by default, even in newer versions.

There is a common belief that because etcd can be encrypted, it is encrypted out of the box. In reality, it remains an opt-in feature to avoid performance overhead. Beginners often skip this step because they think it is already done.

Mistake

The 'system:masters' group is safe to use for cluster administration because it is built-in.

Correct

The 'system:masters' group bypasses RBAC entirely. Anyone in this group has unrestricted super-user access. It should only be used for emergency break-glass scenarios, never for daily administration.

Because the group name sounds official ('system:masters'), beginners think it is the intended way to grant admin access. They do not realise that it is a legacy escape hatch that undermines all RBAC controls.

Do You Actually Know This?

Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.

Frequently Asked Questions

How do I check if the insecure port is still open on my cluster?

Run 'kubectl get pods -n kube-system | grep kube-apiserver' to find the API Server pod, then execute 'kubectl exec -it <pod-name> -n kube-system -- ps aux | grep kube-apiserver' and look for the '--insecure-port' flag. If it shows '--insecure-port=8080', the port is open.

Is it safe to use the default kubeconfig file that the cluster gives me?

No. The default kubeconfig often uses a user in the 'system:masters' group, which bypasses RBAC. You should create dedicated service accounts with specific roles and use those instead for day-to-day operations.

What happens if I forget to enable encryption at rest?

All secrets, passwords, and API keys stored as Kubernetes Secrets will be stored as plaintext in the etcd database. If an attacker gains access to the etcd data directory (e.g., through a backup leak), they can read all sensitive data.

How do I test whether my RBAC rules are working?

Use the 'kubectl auth can-i' command. For example, 'kubectl auth can-i create pods --as=jane' tests whether a user named 'jane' is allowed to create pods. You can also use 'kubectl auth can-i --list' to see all permissions for the current user.

Why does the exam expect me to edit files in /etc/kubernetes/manifests/ directly?

Because the CKS exam uses kubeadm-created clusters where the control plane components run as static pods. Static pods are defined by manifest files in that directory. Editing the manifest file automatically triggers a restart of the component, which simulates a real cluster admin scenario.

Do I need to worry about TLS between the control plane and the workers?

Yes. By default, kubeadm sets up TLS certificates for communication between components, but you must verify that they are in place. Use 'kubectl get pods -n kube-system' and inspect the logs for any TLS handshake errors. The CKS exam often includes a scenario where TLS is missing and you must regenerate certificates.

Terms Worth Knowing

Keep going

You've finished Cluster Setup: Secure Configuration and Best Practices. Continue through the CKS study guide to build a complete picture of the exam.

Done with this chapter?