"Mastering Multi-Cluster Kubernetes: Secure Vault Integration"

Managing Multiple Kubernetes Clusters with Vault: A Comprehensive Guide

In today's dynamic IT landscape, managing multiple Kubernetes clusters has become a necessity for many organizations. While Kubernetes provides a powerful platform for orchestrating containerized applications, securing and managing secrets across multiple clusters can be a complex task. This is where HashiCorp's Vault comes into play. Vault is a secrets management tool that provides a secure and dynamic way to store and manage secrets. In this article, we will explore how to use Vault to manage secrets across multiple Kubernetes clusters.

Understanding Vault and Its Role in Kubernetes

Vault is a tool for securely storing and accessing secrets such as passwords, API keys, and certificates. It provides a unified interface to manage these secrets, enabling fine-grained access control and audit logging. In a Kubernetes environment, Vault can be used to store and manage sensitive data that should not be hardcoded into application code or stored in version control systems.

Vault integrates seamlessly with Kubernetes, providing a Kubernetes Authentication method that allows Vault to authenticate requests using Kubernetes service accounts. This enables a secure and dynamic way to manage secrets, as Vault can automatically generate and rotate secrets based on the Kubernetes service account making the request.

How To Integrate Multiple Kubernetes Clusters to [Guide]
How To Integrate Multiple Kubernetes Clusters to [Guide]

Setting Up Vault for Multiple Kubernetes Clusters

Installing Vault

Before we can start using Vault to manage secrets across multiple Kubernetes clusters, we need to install and configure Vault. The first step is to install Vault on each of the Kubernetes clusters we want to manage. This can be done using Helm, the package manager for Kubernetes, or by manually deploying the Vault StatefulSet.

Here's an example of how to install Vault using Helm:

helm repo add hashicorp https://helm.releases.hashicorp.com
helm install vault hashicorp/vault --set "server.affinity.podAntiAffinity.preference='soft'" --set "server.resources.requests.memory='512Mi'" --set "server.resources.requests.cpu='250m'" --set "server.service.type=ClusterIP" --set "injector.enabled=true" --set "injector.vaultAgentImage='hashicorp/vault-agent:latest'" --set "injector.kubernetesEnableServiceLinks=false" --set "server.standby.enabled=false" --set "server.replicaCount=1

Configuring Vault

Once Vault is installed, we need to configure it to manage secrets for our Kubernetes clusters. This involves setting up Vault policies and secret engines to control access to secrets and define how they are stored and generated.

Déployer ses application dans Kubernetes avec des secrets Vault - OCTO Talks !
Déployer ses application dans Kubernetes avec des secrets Vault - OCTO Talks !

Here's an example of how to configure Vault to use the Kubernetes authentication method and enable the Kubernetes secret engine:

vault auth enable kubernetes
vault write auth/kubernetes/config kubernetes_host="https://${KUBERNETES_SERVICE_HOST}:${KUBERNETES_PORT_443_TCP_PORT}" kubernetes_ca_cert=@/vault/userconfig/kubernetes-ca.crt
vault write auth/kubernetes/role/kubernetes-role bound_service_account_names="default" policies="default" ttl=27h
vault secrets enable -path=kubernetes kubernetes

Managing Secrets Across Multiple Kubernetes Clusters

Storing Secrets in Vault

With Vault configured to use the Kubernetes authentication method and the Kubernetes secret engine enabled, we can start storing secrets in Vault. Secrets can be stored as key-value pairs, with the key being the name of the secret and the value being the secret data itself.

Here's an example of how to store a secret in Vault using the Kubernetes secret engine:

a diagram showing the different types of kubernets and what they are used
a diagram showing the different types of kubernets and what they are used

vault kv put kubernetes/secret/my-secret value="my-secret-value"

Accessing Secrets from Kubernetes

Once a secret is stored in Vault, it can be accessed from Kubernetes using the Vault Agent-sidecar. The Vault Agent-sidecar is a sidecar container that runs alongside the application container and communicates with Vault to retrieve and manage secrets.

The Vault Agent-sidecar can be configured to automatically mount the Kubernetes secret engine and retrieve secrets based on the Kubernetes service account making the request. This enables a dynamic and secure way to manage secrets, as secrets can be automatically generated and rotated based on the service account making the request.

Here's an example of how to configure the Vault Agent-sidecar to mount the Kubernetes secret engine and retrieve secrets:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
spec:
  selector:
    matchLabels:
      app: my-app
  template:
    metadata:
      labels:
        app: my-app
    spec:
      serviceAccountName: my-app
      containers:
      - name: my-app
        image: my-app:latest
      - name: vault-agent
        image: hashicorp/vault-agent:latest
        env:
        - name: VAULT_ADDR
          value: "https://vault.example.com"
        - name: VAULT_SKIP_VERIFY
          value: "true"
        - name: VAULT_K8S_PATH
          value: "kubernetes/secret"
        - name: VAULT_K8S_ROLE
          value: "kubernetes-role"
        - name: VAULT_K8S_SERVICE_ACCOUNT_TOKEN
          value: "/var/run/secrets/kubernetes.io/serviceaccount/token"

Best Practices for Managing Secrets with Vault

When using Vault to manage secrets across multiple Kubernetes clusters, there are several best practices that should be followed to ensure the security and reliability of the system:

  • Use Fine-Grained Access Control: Vault provides fine-grained access control using policies. Policies should be used to define exactly what access each Kubernetes service account has to secrets in Vault.
  • Enable Audit Logging: Vault provides audit logging to track access to secrets in Vault. Audit logging should be enabled and configured to log all access to secrets.
  • Rotate Secrets Regularly: Vault provides automatic secret rotation, which should be enabled to ensure that secrets are rotated regularly and are not reused.
  • Use Vault's Dynamic Secret Generation: Vault provides dynamic secret generation, which enables secrets to be generated on-the-fly based on the requesting service account. This enables a more secure and dynamic way to manage secrets.
  • Monitor Vault's Health: Vault provides health checks and metrics that can be used to monitor the health of the Vault cluster. These should be monitored to ensure that Vault is running smoothly and that secrets are being managed correctly.

Conclusion

Managing secrets across multiple Kubernetes clusters can be a complex task, but Vault provides a powerful and secure way to do so. By using Vault's Kubernetes authentication method and Kubernetes secret engine, secrets can be stored and managed dynamically and securely. By following best practices for using Vault, organizations can ensure the security and reliability of their secrets management system.

Maximise Your Productivity: Harness Hot Reloading in Kubernetes
Maximise Your Productivity: Harness Hot Reloading in Kubernetes
¿Qué es Kubernetes? | Microsoft Azure
¿Qué es Kubernetes? | Microsoft Azure
What Is Kubernetes? A Guide to Containerization and Deployment | Toptal®
What Is Kubernetes? A Guide to Containerization and Deployment | Toptal®
how kubernets works end - to - end with the blueprinting application
how kubernets works end - to - end with the blueprinting application
Kubernetes
Kubernetes
the kubernets cheat sheet is shown in blue and white with text on it
the kubernets cheat sheet is shown in blue and white with text on it
Best AI Kubernetes Incident Management Tools
Best AI Kubernetes Incident Management Tools
the logo for digital ocean's kubernets, which is designed to look like
the logo for digital ocean's kubernets, which is designed to look like
Openshift vs Kubernetes - ClickIT
Openshift vs Kubernetes - ClickIT
Why Multi Tenancy in Kubernetes Matters for Enterprises?
Why Multi Tenancy in Kubernetes Matters for Enterprises?
the cover of traffic routing in kubernets, with four different types of information
the cover of traffic routing in kubernets, with four different types of information
🛡️ Enhancing Cluster Security with RBAC in Kubernetes 🛡️
🛡️ Enhancing Cluster Security with RBAC in Kubernetes 🛡️
KUBERNETES ROADMAP (2026)
KUBERNETES ROADMAP (2026)
Mastering your Kubernetes Cluster - the kubectl exec Command
Mastering your Kubernetes Cluster - the kubectl exec Command
KimberLite Diamond Vault
KimberLite Diamond Vault
Kubernetes Architecture: Inside the Worker Node
Kubernetes Architecture: Inside the Worker Node
traffic routing in kubernets and ingress with the caption below it
traffic routing in kubernets and ingress with the caption below it
the architecture diagram for kubernets architecture
the architecture diagram for kubernets architecture
Kubernetes for ASP.NET Core Developers – Introduction, Architecture, Hands-On
Kubernetes for ASP.NET Core Developers – Introduction, Architecture, Hands-On
reddubs kubernets solution for windows and mac is shown in this screenshot
reddubs kubernets solution for windows and mac is shown in this screenshot
Unveiling The Benefits Of Kubecost In Optimizing Kubernetes Costs
Unveiling The Benefits Of Kubecost In Optimizing Kubernetes Costs
Investigating Kubernetes from Inside | Apriorit
Investigating Kubernetes from Inside | Apriorit
Kubernetes Resource Usage Monitoring
Kubernetes Resource Usage Monitoring