TNS
VOXPOP
Where are you using WebAssembly?
Wasm promises to let developers build once and run anywhere. Are you using it yet?
At work, for production apps
0%
At work, but not for production apps
0%
I don’t use WebAssembly but expect to when the technology matures
0%
I have no plans to use WebAssembly
0%
No plans and I get mad whenever I see the buzzword
0%
Kubernetes / Microservices / Security

Securing Microservices Communication with mTLS in Kubernetes

Microservices often communicate with each other to fulfill complex business operations, creating security and scaling challenges. Mutual Transport Layer Security (mTLS) can help. Here's how to get started.
Nov 28th, 2023 3:00am by
Featued image for: Securing Microservices Communication with mTLS in Kubernetes
Image by Pavan Trikutam from Unsplash.

Kubernetes, the de facto orchestration platform for containerized applications, provides a powerful environment for deploying and managing microservices. But as the number of interconnected services grows, the need for a robust security mechanism becomes increasingly critical.

Microservices often communicate with each other to fulfill complex business operations. This communication involves the exchange of sensitive data such as user credentials, payment information and personal identifiers.

In the absence of proper security measures, this data can be intercepted or tampered with, leading to privacy breaches and compromised integrity. Additionally, the dynamic nature of microservices and their constant scaling demands a security solution that is agile and automated.

Mutual Transport Layer Security (mTLS) has emerged as a powerful solution to address these security challenges.

mTLS builds upon the foundation of the Transport Layer Security (TLS) protocol, commonly known for securing communication over the internet using encryption. However, mTLS takes security a step further by enforcing mutual authentication between communicating parties.

In other words, both the client and the server are required to present valid digital certificates, ensuring not only encrypted but also authenticated communication.

mTLS and Kubernetes

Kubernetes provides the perfect platform for implementing mTLS due to its dynamic service discovery and management capabilities. With services frequently being added, removed or scaled within a Kubernetes cluster, mTLS ensures that every new instance is authenticated before it can communicate with other services.

This creates a robust security foundation, allowing developers to focus on building features without compromising the integrity and privacy of data flowing between microservices.

In this article, we will dive into the practical implementation of mTLS within a Kubernetes cluster. We will leverage Istio, an open source service mesh that provides advanced networking and security features for microservices.

Prerequisites for Implementing mTLS in Kubernetes

Before you begin implementing mTLS in your Kubernetes cluster, ensure you have the following prerequisites in place.

  • A Kubernetes cluster. You should have a functioning Kubernetes cluster up and running. This can be a local cluster set up using tools like Minikube or a cloud-managed Kubernetes environment like Google Kubernetes Engine (GKE), Amazon Elastic Kubernetes Service (EKS), or Microsoft Azure Kubernetes Service (AKS).
  • Kubectl. Make sure you have the kubectl command-line tool installed and properly configured to interact with your Kubernetes cluster. This tool will be used to manage and interact with the cluster resources.
  • Basic Kubernetes knowledge. A fundamental understanding of Kubernetes concepts such as pods, services, deployments and namespaces is essential. You should be comfortable creating, managing, and deleting these resources using kubectl commands.
  • Containerized microservices. Prepare the container images for the microservices you intend to deploy in the tutorial. These images should be hosted on a container registry accessible to your Kubernetes cluster.
  • Istio installation. Since we’ll be using Istio for implementing mTLS, you need to have Istio installed in your Kubernetes cluster. Follow the Istio installation documentation relevant to your environment.
  • Helm (optional but recommended). Helm is a package manager for Kubernetes that simplifies the deployment of applications and services. While not strictly required, using Helm can streamline the installation of complex applications like Istio. If you’re using Helm, ensure it’s installed and configured.
  • Valid domain names. Istio’s mTLS features often rely on valid domain names to generate certificates. If you’re setting up mTLS for a production-like environment, having valid domain names (or using wildcard certificates) will help ensure a smoother implementation.
  • Access to Istio’s documentation. Keep the official Istio documentation handy. It will be your go-to resource for configuring Istio’s features, including mTLS.

Note: This tutorial assumes that you are working in a controlled environment for learning and experimentation. Implementing security measures like mTLS in a production environment involves careful planning, coordination, and potentially additional security measures. Always refer to best practices and security guidelines relevant to your specific use case.

Got all these prerequisites in place? Then let’s get started.

Step 1: Install Istio

Istio acts as a service mesh, providing a layer of control and observability to services in a Kubernetes cluster. It simplifies the implementation of security features like mutual TLS while offering traffic management, load balancing and more.

To install Istio, you can use its official installation tool istioctl.

Download Istio:


Move to the Istio package directory:


Add Istio to your PATH:


Install Istio to your Kubernetes cluster:

Step 2: Deploy Sample Services

Let’s begin by setting up sample services. We’ll simulate two microservices, Service A and Service B, to showcase secure communication. These services will later be configured to communicate using mTLS.

Deploying Using Kubernetes Deployment

In Kubernetes, a Deployment resource is ideal for managing the life cycle of your applications. Deploy both Service A and Service B using deployment YAML files, which define how many instances to run and how they should be managed.


Similar YAML for Service B.

Enabling Sidecar Injection

Istio leverages sidecar containers to inject features like mTLS into your application pods. Annotate the deployment with sidecar.istio.io/inject: "true"

Step 3: Configure mTLS

Istio’s DestinationRule resource is crucial for configuring mTLS. It allows you to define traffic policies, including security settings like TLS modes. Here’s how to create a DestinationRule to enforce mTLS:

Step 4: Generate Certificates

Automating the certificate generation process is a critical function of Istio’s Citadel component, particularly in the context of establishing secure connections through mTLS. These digital certificates play a fundamental role in facilitating secure communication between services within the Istio mesh.

The Citadel ensures that each service within this mesh possesses a valid certificate, a crucial requirement for the mutual authentication aspect of mTLS. This authentication necessitates both the client and the server to present valid certificates, thereby fortifying the security of their connection.

This automation goes beyond mere convenience, significantly reducing manual overhead associated with the creation, distribution and renewal of certificates. By automating certificate management, potential human errors are mitigated, and the entire process is streamlined.

The Citadel’s role in eliminating manual intervention not only enhances operational efficiency but also contributes to the reliability of the security infrastructure.

Furthermore, the automated approach ensures consistency across the entire cluster. All services integrated into the Istio mesh receive up-to-date certificates, fostering a uniform and secure communication environment. This consistency is pivotal for maintaining a robust security posture, particularly in dynamic and distributed architectures.

Step 5: Verify Secure Communication

Using Port-Forwarding

To verify secure communication, use Kubernetes port-forwarding to access the deployed services locally:

Monitoring with Observability Tools

Istio provides observability tools like Kiali and Grafana to monitor mTLS traffic. These tools offer insights into traffic flow, security policies and communication trends.

Step 6: Clean Up

Resource Cleanup

After testing mTLS, it’s essential to clean up resources to prevent unnecessary resource consumption. Delete the services, deployments, Istio configurations and disable Istio’s sidecar injection.


By following these steps, you will have successfully implemented mTLS to enhance the security of communication between microservices within your Kubernetes cluster.

Remember that while this tutorial provides a comprehensive guide, the actual process may vary based on your specific environment and requirements. Always consult Istio’s official documentation for the latest guidance.

What’s Next?

As you delve into the world of mTLS, explore the broader spectrum of benefits that a service mesh like Istio offers. Istio extends beyond mTLS, providing a comprehensive suite of security and observability tools. It bestows granular control over traffic, facilitates robust access control policies and provides real-time insights into your service mesh’s behavior.

Exploring these facets not only cements your microservices communication but also equips you with a powerful toolkit for enhancing overall system security and monitoring.

By encrypting communication within a Kubernetes environment, harnessing the potency of mTLS, and checking out Istio’s broader features, you’re not just fortifying the foundation of your microservices architecture but also embracing a holistic approach to secure, efficient and resilient application development.

Group Created with Sketch.
THE NEW STACK UPDATE A newsletter digest of the week’s most important stories & analyses.