SBN

Kubernetes Security Risks and Critical Best Practices

What is Kubernetes security?

Kubernetes security refers to practices, tools, and configurations that protect Kubernetes clusters and workloads from unauthorized access, vulnerabilities, and runtime threats. It involves securing all components of the Kubernetes environment—including the control plane, worker nodes, pods, container images, networking, and storage. 

Kubernetes introduces a unique attack surface, and securing it involves controlling access to the API server, enforcing authentication and authorization policies, securing data in transit and at rest, and monitoring system behavior to detect anomalies.

Effective Kubernetes security also requires securing the software supply chain, enforcing least privilege across users and services, and implementing runtime protection mechanisms. Because Kubernetes manages ephemeral, dynamic containerized environments, security strategies must be continuous and adaptive, spanning build, deployment, and production phases. This means integrating security deeply into CI/CD pipelines, continuously scanning workloads, and automating policy enforcement across infrastructure.

Cloud-native security layers

Why is Kubernetes security so important?

Recent data underscores the critical need for robust Kubernetes security measures:

  • Deployment delays due to security concerns: 67% of organizations have postponed or slowed down application deployments because of security issues in their Kubernetes environments.
  • Business impact from security incidents: 46% of surveyed organizations experienced revenue or customer loss due to container and Kubernetes security incidents.
  • Widespread security incidents: 58% of organizations reported experiencing a container or Kubernetes-related security incident in the past year, with nearly a third facing multiple incidents.
  • Increased risk exposure: 37% of respondents admitted they’ve had to delay security updates or patches due to resource limitations, leaving clusters vulnerable to known threats.
  • Misconfiguration as a primary risk: Misconfigurations remain the leading cause of Kubernetes security incidents, cited by over half of the respondents, emphasizing the importance of proper configuration management and policy enforcement.

These statistics highlight the necessity for comprehensive security strategies in Kubernetes environments to prevent disruptions, financial losses, and reputational damage.

Sources: Red Hat, CNCF 

Kubernetes security risks and the DevOps pipeline

Another way to think more specifically about Kubernetes security from a developer point of view is to look at it across three distinct stages of the DevOps pipeline:

  • Creating the container image during the build
  • Configuring the Kubernetes infrastructure during deployment
  • Securing network communication in production

Kubernetes security risks during build

Kubernetes security begins in the build stage when writing the code that becomes the container image. Although Kubernetes isn’t necessarily involved during the build and packaging stage, a secure environment starts with assessing the risk associated with any code being deployed. Application security best practices and testing are important here, and any effort to shift security left will pay dividends by avoiding future problems in deployment and production.

In this stage, you need to make sure that your container image is up to date, free from security vulnerabilities, and is compliant with your licensing policies. Containers are built in layers, and often have no canonical list of what open source components have been included in the final build of the container image. To address this, you need to scan containers to determine which open source libraries are in play inside the application, including going through any dependencies that are brought in through a package manager like Maven or npm. 

By discovering and identifying all open source components in play, you can identify any known vulnerabilities, establish which images are at risk as new vulnerabilities are discovered, and track the licenses associated with specific libraries. Tracking license compliance may not be a security risk, but it can have a downstream effect, like exposing proprietary code if an incompatible license is included.

Ensuring your base images are regularly scanned is the first step to securing your Kubernetes environment. 

Kubernetes security risks during deployment 

When deploying Kubernetes, you are given a powerful set of controls to secure clusters and their applications. Configuring these controls requires an intimate knowledge of Kubernetes as well as the deployment’s security requirements. Don’t use defaults! It only leads to unnecessary (and perhaps even negligent) exposure. At the very least, you should limit the scope of user permissions, limit direct access to Kubernetes nodes, and create network segmentation so that containers communicate only with the containers they are supposed to.

Scanning at this stage remains of paramount importance. Container images must be built using secure base images. You need to implement continuous security vulnerability scanning and regularly apply security updates to your environment. Scanning is not a one-off event. In addition, when launching containers in your Kubernetes environment, only use images from image registries on allow lists.

Kubernetes security risks in production

Application security in runtime is very different from the build stage. Notably, network security is more complex. Best practices for network security in Kubernetes go beyond basic networking and leverage the container network interface (CNI) to implement a more robust networking layer that includes either multi-tenant support, network policies, or both.

With a multi-tenant network, each namespace within the Kubernetes cluster gets a private addressable subnet and can only access pods in other namespaces that are specifically exposed as services. Open vSwitch is a great example of a networking layer for Kubernetes that has multi-tenant support.

Network policies in most next-generation networking layers are available to be deployed via Kubernetes. Project Calico is an example of a widely used networking layer that has been built from the ground up to support network policies with containers. Network policies allow cluster administrators to predefine network access control lists that control which ports are accessible and which services can be accessed.

Kubernetes security best practices during build, deploy, and runtime.

10 Kubernetes security best practices

Here are the most important best practices that can help you improve the security posture of Kubernetes clusters.

1. Image scanning

Image scanning is essential to identify vulnerabilities in container images before they are deployed into production environments. Modern container images often rely on layers of open source software, each of which may introduce vulnerabilities. Platforms like Mend can be integrated into CI/CD pipelines to automatically detect known CVEs (Common Vulnerabilities and Exposures), outdated packages, misconfigurations, and risky software licenses. These scans should not be a one-time activity but part of a continuous integration and delivery process to catch regressions and newly disclosed vulnerabilities.

In addition to security risks, image scanning can help enforce policy compliance, ensuring that only images built from approved base images and with known components are allowed into production. Container image signatures and attestations can be used to verify image integrity and provenance, preventing tampered or untrusted images from being pulled into the cluster. Keeping a Software Bill of Materials (SBOM) also provides traceability, helping teams assess and mitigate risks quickly when new vulnerabilities are disclosed in upstream dependencies.

2. Enable role-based access control (RBAC)

Role-Based Access Control (RBAC) is a Kubernetes feature that allows administrators to specify which users or services can access which resources, and in what way. By assigning roles to users based on their responsibilities and binding those roles to specific namespaces or resources, you reduce the risk of over-permissioned accounts and minimize the impact of a compromised credential. Default roles like cluster-admin should be used sparingly, and developers should be given the minimum access necessary to perform their tasks.

RBAC policies should be reviewed regularly, especially after changes in team structures, deployments, or security incidents. Tools such as rbac-lookup, rakkess, and Kubernetes Policy Controller can help visualize and audit RBAC configurations. By combining RBAC with other access control mechanisms like namespace isolation and network policies, organizations can build a defense-in-depth strategy that significantly strengthens their Kubernetes security posture.

3. Use third-party authentication for API server

Integrating Kubernetes with an external identity provider (IdP) using OpenID Connect (OIDC) allows for centralized authentication and better user management. This makes it easier to enforce security policies such as multi-factor authentication (MFA), single sign-on (SSO), and user deprovisioning. Popular IdPs like Okta, Auth0, Azure AD, and Google Identity provide scalable identity management that supports auditing and compliance requirements.

Using third-party authentication also eliminates the need to manage user credentials directly in the cluster, reducing the risk of mismanagement or credential sprawl. When integrated properly, the Kubernetes API server uses tokens issued by the IdP, and RBAC policies can then be enforced based on identity group membership. This makes it easier to align Kubernetes access with corporate IT standards and improve traceability of user actions through centralized logs.

4. Protect etcd with TLS and firewall

The etcd database is the central store for all cluster data, including configurations, secrets, and credentials. Unauthorized access to etcd can lead to a complete cluster compromise. To secure etcd, encrypt communication with TLS, and enable client authentication using certificates. This ensures that only trusted components can interact with the data store and helps prevent man-in-the-middle attacks or data leaks.

Beyond encryption, etcd should be network-isolated using firewalls or security groups to allow access only from the Kubernetes API server. Avoid exposing etcd on public networks or untrusted segments. It’s also critical to enable encryption at rest for the etcd data store and ensure regular, encrypted backups are taken and stored securely. Periodic testing of the restore process is also necessary to ensure business continuity in case of corruption or data loss.

5. Isolate Kubernetes nodes

Node isolation helps reduce the blast radius of a security incident. By using Kubernetes taints and tolerations, administrators can assign specific workloads to designated node groups. For instance, public-facing workloads can be scheduled on nodes without access to internal databases or APIs, minimizing cross-contamination risks. Similarly, sensitive workloads like payment services can be isolated from general-purpose services to enhance security.

Cloud providers also offer mechanisms like subnets, VPCs, and security groups that can be used to further isolate node groups. These can enforce firewall rules that prevent unauthorized access between different classes of nodes or between nodes and the internet. Implementing node isolation along with network segmentation and service mesh policies can provide a layered security model that is resilient to lateral movement and privilege escalation attacks.

6. Monitor network traffic to limit communications

By default, Kubernetes networking allows all pods to talk to each other, which creates unnecessary risk in the event of a compromise. Implementing Kubernetes network policies restricts communication between pods, services, and namespaces. Policies can be enforced using CNI plugins like Calico, Cilium, or Weave, which let administrators define explicit rules about which services are allowed to talk to each other.

Continuous monitoring of network traffic is essential to identify misconfigurations, potential intrusions, or anomalous behavior. Tools like Istio, Linkerd, or commercial service meshes offer observability features like traffic tracing, latency metrics, and access logging. These tools can help you fine-tune policies and quickly detect security breaches, allowing teams to respond before attackers move deeper into the cluster.

7. Use process allowlisting

Process allowlisting restricts containers to run only specific, predefined applications or system calls. This limits an attacker’s ability to exploit a container even if it’s compromised. Technologies like AppArmor, Seccomp, and SELinux allow administrators to define these restrictions in the form of policies or profiles. For example, a Seccomp profile can block the use of certain Linux system calls, significantly reducing the container’s attack surface.

Process-level enforcement helps prevent misuse of container environments for activities like crypto mining, reverse shells, or privilege escalation. Unlike traditional antivirus or endpoint detection tools, these kernel-level mechanisms operate with minimal performance impact and are highly effective in resource-constrained environments like containers. 

8. Turn on audit logging

Audit logging in Kubernetes records all interactions with the API server, providing visibility into who accessed what resources and what actions were performed. This is critical for forensic analysis, incident response, and meeting compliance requirements such as HIPAA or PCI-DSS. Audit logs can be configured to include events such as read, write, or access denied, and filtered based on namespaces, user roles, or resource types.

Logs should be collected and stored in a secure, centralized system. This allows for log correlation, threat detection, and long-term archival. Regular review of audit logs can help detect suspicious behavior, such as privilege escalation attempts or unauthorized access to sensitive resources, and is a key component of any proactive security monitoring strategy.

9. Keep Kubernetes version up to date

Each Kubernetes release includes patches for known vulnerabilities and improvements to security features. Running outdated versions exposes your cluster to risks that attackers are aware of and actively exploit. Kubernetes maintains a rapid release cycle, and organizations should follow a structured upgrade process to stay current while minimizing downtime and disruption.

Before upgrading, always test new versions in a staging environment to identify compatibility issues with workloads or third-party integrations. Use tools like kubeadm or rely on managed services that automate parts of the upgrade process. Staying up to date also means keeping track of deprecated APIs and changes in default behavior, which could affect application performance or availability if not addressed.

10. Lock down kubelet

The kubelet is a powerful component that manages pod lifecycle operations on each node. It exposes a REST API that can be misused if not properly secured. By default, the kubelet allows access to the /exec, /logs, and /metrics endpoints, which can be exploited to view logs or inject commands into running containers. Disabling anonymous access and enabling authentication and authorization are critical first steps to lock it down.

Additionally, limit access to the kubelet API by binding it to 127.0.0.1 or by protecting it with a firewall. Avoid using overly permissive flags like --read-only-port and audit kubelet configurations regularly. It’s also recommended to enable kubelet security settings like --tls-cert-file, --authentication-token-webhook, and --authorization-mode=Webhook to enforce identity verification and access control for incoming requests.

Improving Kubernetes security with Mend.io

Securing your Kubernetes deployed applications requires a holistic approach that effectively leverages container security across the entire SDLC.  Mend.io’s Kubernetes integration creates visibility into potential risks by scanning for vulnerabilities in container images, with:

Container reachability identifies which vulnerable files and methods are being called at runtime without needing runtime agents, allowing you to safely deprioritize more unreachable vulnerabilities.

Development to deployment security extends protection across the software development lifecycle. It starts by scanning static images in your pipeline and continues to analyze container behavior for security risks at runtime.

Secrets detection identifies exposed credentials, passwords, keys, and certificates within an image, addressing the critical need for securing sensitive data.

Kubernetes cluster scanning effortlessly scans all running container images within your Kubernetes clusters, making it easy to find and label containers that are actively in use and deployed.

Learn more about Mend.io’s Kubernetes security.

*** This is a Security Bloggers Network syndicated blog from Mend authored by Mend.io Team. Read the original post at: https://www.mend.io/blog/kubernetes-security/