DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Building Secure Containers: Reducing Vulnerabilities With Clean Base Images
  • Docker vs. Podman: Exploring Container Technologies for Modern Web Development
  • The Role of Kubernetes Security in the Immediate Future of Computing
  • Guide to Cloud-Native Application Security

Trending

  • Apache Doris vs Elasticsearch: An In-Depth Comparative Analysis
  • Zero Trust for AWS NLBs: Why It Matters and How to Do It
  • Failure Handling Mechanisms in Microservices and Their Importance
  • Rust and WebAssembly: Unlocking High-Performance Web Apps
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Maximize Kubernetes Security: Automate TLS Certificate Management With Cert-Manager on KIND Clusters

Maximize Kubernetes Security: Automate TLS Certificate Management With Cert-Manager on KIND Clusters

Effortlessly manage TLS certificates in Kubernetes with cert-manager. Enhance security and streamline deployments with automated certificate issuance and renewal.

By 
Rajesh Gheware user avatar
Rajesh Gheware
DZone Core CORE ·
Mar. 30, 24 · Opinion
Likes (1)
Comment
Save
Tweet
Share
2.4K Views

Join the DZone community and get the full member experience.

Join For Free

In the realm of Kubernetes, managing certificates effectively is pivotal for ensuring the security and integrity of the communication between different components within the cluster. With the advent of cloud-native technologies, the complexity and dynamism of service deployments have escalated, making traditional certificate management approaches cumbersome and inefficient. This article introduces cert-manager, a Kubernetes add-on, as a solution to automate the management of TLS certificates, enhancing security while reducing manual intervention and potential human errors. Our focus will be on deploying and managing certificates in a KIND-based Kubernetes cluster.

Introduction to Cert-Manager

Cert-manager is an open-source Kubernetes tool designed to automate the issuance, renewal, and management of TLS certificates from various issuing sources such as Let's Encrypt, HashiCorp Vault, Venafi, simple signing key pairs, or self-signed. It ensures that certificates are valid and up to date, and attempts to renew certificates at a configured time before expiration.

Setting up a KIND-Based Kubernetes Cluster

KIND (Kubernetes IN Docker) is a tool for running local Kubernetes clusters using Docker container "nodes." KIND was primarily designed for testing Kubernetes itself, but may be used for local development or CI.

To create a cluster, ensure you have Docker and KIND installed on your system. Then, use the following command:

Lua
 
kind create cluster


This command creates a default cluster named "kind". You can specify a configuration file to customize the cluster further.

Installing Cert-Manager

Before installing cert-manager, ensure your Kubernetes cluster is up and running. You can verify this with kubectl get nodes. Once confirmed, proceed with the following steps to install cert-manager.

Step 1: Install the Custom Resource Definitions (CRDs)

Shell
 
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.6.1/cert-manager.crds.yaml


Step 2: Add the Jetstack Helm Repository

C#
 
helm repo add jetstack https://charts.jetstack.io


Step 3: Update Your Local Helm Chart Repository Cache

CSS
 
helm repo update


Step 4: Install Cert-Manager

CSS
 
helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.6.1


This installs cert-manager in the cert-manager namespace and ensures isolation from other applications.

Configuring Cert-Manager for Automatic Certificate Management

After installing cert-manager, the next step is to configure it to automate certificate issuance and renewal. This involves creating Issuers or ClusterIssuers resources, which represent entities that issue certificates, and Certificate resources to request certificates from the Issuers.

Example: Configuring a ClusterIssuer for Let's Encrypt

YAML
 
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-prod
spec:
  acme:
    email: your-email@example.com
    server: https://acme-v02.api.letsencrypt.org/directory
    privateKeySecretRef:
      name: letsencrypt-prod
    solvers:
    - http01:
        ingress:
          class: nginx


Replace your-email@example.com with your email address. This configuration uses the ACME protocol with HTTP-01 challenge to validate domain ownership.

Requesting a Certificate

After defining an Issuer or ClusterIssuer, you can request a certificate by creating a Certificate resource:

YAML
 
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: example-com
  namespace: default
spec:
  secretName: example-com-tls
  issuerRef:
    name: letsencrypt-prod
    kind: ClusterIssuer
  dnsNames:
  - example.com
  - www.example.com


This request generates a certificate for example.com and www.example.com, storing it in a Kubernetes secret named example-com-tls.

Automating Certificate Renewal

The cert-manager automatically monitors and renews certificates based on their validity period. Typically, certificates are renewed 30 days before expiration. No additional configuration is needed beyond the initial setup.

Automating Ingress Certificate Management With Cert-Manager

One of the most powerful features of cert-manager is its ability to automatically issue certificates for Kubernetes Ingress resources, simplifying the process of securing your applications with HTTPS. This capability allows developers to automatically secure their applications without the need to manually create and renew certificates for each Ingress. Here, we'll delve into how to set up an Ingress resource to automatically request and apply certificates using a cert-manager.

Step 1: Define an Ingress Resource

First, ensure your Kubernetes cluster has an Ingress controller installed. The Nginx Ingress Controller is a common choice and can be deployed from the Kubernetes official documentation or through Helm charts.

With an Ingress controller in place, define your Ingress resource. Here's an example that routes traffic to a sample web application:

YAML
 
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web-application
  annotations:
    cert-manager.io/cluster-issuer: "letsencrypt-prod"
    kubernetes.io/ingress.class: "nginx"
spec:
  rules:
  - host: example.com
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web-application-service
            port:
              number: 80
  tls:
  - hosts:
    - example.com
    secretName: example-com-tls


In this Ingress definition, note the following key points:

  • The cert-manager.io/cluster-issuer annotation specifies the ClusterIssuer to use for obtaining a certificate. Replace "letsencrypt-prod" with the name of your ClusterIssuer.
  • The kubernetes.io/ingress.class annotation is set to "nginx", indicating that this Ingress should be handled by the Nginx Ingress Controller.
  • The TLS section requests a TLS certificate for the host example.com, which the cert-manager will automatically provision and store in the specified secretName. The only condition is that the domain must be accessible over the Internet.

Step 2: Deploy the Ingress Resource

Deploy the Ingress resource to your cluster using kubectl apply -f ingress.yaml, where ingress.yaml is the file containing the Ingress resource definition.

Step 3: Automatic Certificate Issuance

Upon deployment, the cert-manager detects the new Ingress resource and reads the annotations to understand that a certificate is requested. It then communicates with the specified ClusterIssuer to issue a certificate for the hosts defined under the TLS section. The process involves:

  • Performing domain validation as per the ClusterIssuer's configuration (e.g., HTTP-01 challenge for Let's Encrypt).
  • Once validated, the cert-manager obtains the certificate and stores it in the specified Kubernetes secret (example-com-tls in this case).
  • The Ingress controller then uses the certificate from the secret to secure traffic to the example.com domain.

Step 4: Verifying the Certificate

After a few minutes, you can verify that the certificate has been successfully applied by accessing your application over HTTPS (https://example.com) and checking the certificate details. Additionally, you can inspect the Kubernetes secret (example-com-tls) to see the certificate and private key:

YAML
 
kubectl get secret example-com-tls -o yaml


By automating certificate issuance and renewal for Ingress resources, the cert-manager significantly simplifies the process of securing Kubernetes applications. Developers can focus on their application's functionality, knowing that their Ingress URLs are automatically secured with valid TLS certificates. This approach not only enhances security but also streamlines deployment workflows, making it an essential practice for modern Kubernetes-based applications.

Conclusion

Integrating cert-manager into your KIND-based Kubernetes cluster significantly simplifies TLS certificate management, automating issuance, renewal, and deployment of certificates. This not only enhances security but also reduces the operational overhead associated with manual certificate management. By following the steps outlined in this guide, developers and administrators can ensure that their services are always secured with valid certificates, allowing them to focus on building and deploying applications rather than managing infrastructure details.

Remember, while the cert-manager automates many aspects of certificate management, it's essential to monitor its operations, especially in production environments, to handle any unforeseen issues promptly. Embracing tools like cert-manager reflects a strategic approach toward maintaining robust security practices in cloud-native ecosystems, aligning with the broader goal of leveraging technology for competitive advantage and innovation.

Kubernetes clusters Docker (software) security

Published at DZone with permission of Rajesh Gheware. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Building Secure Containers: Reducing Vulnerabilities With Clean Base Images
  • Docker vs. Podman: Exploring Container Technologies for Modern Web Development
  • The Role of Kubernetes Security in the Immediate Future of Computing
  • Guide to Cloud-Native Application Security

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!