How to Effortlessly Automate SSL Deployment with Lego and Kubernetes

Automate SSL certificate management seamlessly with Lego and Kubernetes. Learn efficient deployment practices for a secure web environment at CommIT Smart...

Challenges of manual SSL certificate renewal in Kubernetes with Let's Encrypt

One of our partners runs a huge system on Kubernetes. Using Let's Encrypt, we issued SSL certificates. These certificates are valid for 90 days, then you need to renew them and issue new ones. These certificates were attached to front-end applications in Kubernetes Secrets. Due to the fact that these certificates were issued manually, they may have expired since the issuer forgot to issue a new one.

Our Kubernetes secrets are stored in gitlab. 'Sops' encrypts these secrets. This repository contained the actual certificates, and if a new certificate was issued and the issuer failed to replace the old certificate in the cluster secret but forgot to do so in the GitLab repository, the old certificate would override the new certificate when the secrets were deployed from the repository. Thereafter, the websites became unreliable and started throwing SSLHandshakeErrors. This isn't what we want.

Simplifying certificate operations: achieving automation and flexibility in Kubernetes

We wanted to find a way to issue, manage, and renew these certificates automatically to avoid the problems mentioned above. We were able to easily add new domains to handle their certificates, alongside the automaticity.

The solution

The solution’s main component is Lego. It’s a Let’s Encrypt client and ACME library written in Go.

Lego github repository

We use Lego as a Job(for creating certificates) and Cronjob(for renewing certificates) in our Google GKE cluster. We use Persistent Volumes to mount the certificates to the necessary Pods. To obtain certs we use our DNS provider. Lego has a really wide range of compatibility for DNS providers. The workflow is if we need to manage a new certificate or wildcard certificate, then first we specify a Kubernetes Job to execute Lego with the run command. Lego solves a DNS-01 challenge using the specified provider. If it has a positive outcome, then Lego creates the certificate. After that we only need to specify a Kubernetes Cronjob with the renew command to check the expiry of the certificate periodically.

The implementation

The implementation was the follows:

  1. First we need to create a Persistent Volume and a Persistent Volume Claim to specify for Lego where to put certs.

  2. After it, apply PV and PVC with kubectl.

  3. If these are done, then we can go ahead to write our Job

apiVersion: batch/v1
kind: Job
metadata:
  name: lego-cert-creation
spec:
  ttlSecondsAfterFinished: 120
  template:
    spec:
      containers:
      - name: lego-cert-creation
        image: goacme/lego:<LEGO_VERSION>
        env:
          - name: DNSMADEEASY_API_KEY
            valueFrom:
              secretKeyRef:
                key: apiKey
                name: dnsmadeeasy-secret
          - name: DNSMADEEASY_API_SECRET
            valueFrom:
              secretKeyRef:
                key: secretKey
                name: dnsmadeeasy-secret
        args:
        - --accept-tos
        - --domains=<DOMAIN>
        - --email=<EMAIL>

ttlSecondsAfterFinished: After finishing the job, it will be deleted after 120 seconds.

  • <LEGO_VERSION>: The Lego version you want to use for Lego

  • Env: in the env section we use a secret we deployed to the cluster which contains the necessary data for Lego to be able to communicate with the DNS provider. We use DNSMadeEasy, but other providers may need other data to be able to communicate with their API.

  • args: — accept-tos: By setting this flag to true you indicate that you accept the current Let’s Encrypt terms of service. (default: false) — domains: The domain you want to issue the certificate. If you want to issue certificates for multiple domains you just need to define a –domains argumentum for each domain. You can use a wildcard certificate here. — email: Email used for registration and recovery contact for Let’s Encrypt. — path: Directory to use for storing the data. (default: “./.lego”). It’s **/lego **since we attached the PV into that path inside the container. — dns: The DNS provider you want to use.

  • run: Register an account, then create and install a certificate.

  1. The Cronjob for renewing the certificate looks very similar to the Job

apiVersion: batch/v1
kind: CronJob
metadata:
  name: lego-cert-renewal-cronjob
spec:
  schedule: 1 7 * * 1
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: lego-renewal
            image: goacme/lego:<LEGO_VERSION>
            env:
              - name: DNSMADEEASY_API_KEY
                valueFrom:
                  secretKeyRef:
                    key: apiKey
                    name: dnsmadeeasy-secret
              - name: DNSMADEEASY_API_SECRET
                valueFrom:
                  secretKeyRef:
                    key: secretKey
                    name: dnsmadeeasy-secret
            args: 
            - --accept-tos
            - --domains=<DOMAIN>
            - --email=<EMAIL>

  • Schedule: A cron schedule. We set the job to run every Monday at 7:01 AM.

  • Args: — renew: Renew a certificate. Let’s Encrypt certificates are valid for 90 days. It renews a certificate if it expires in less than 30 days.

  1. After applying Cronjob too, we must make sure that our services use these certificates. As a result, if I used the sandbox API key and secret, it did not work, so if you are implementing this solution, you should use the real credentials.

The conclusion

Using this solution, we can create and maintain SSL certificates automatically. In the future, there won’t be issues because of the expired certs. Lego is very easy to use and supports a wide range of DNS providers.

Author: Csaba Ujvári

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

Jun 20, 2024

Search Query Validation with React Router 6 and Yup and Typescript

Do you validate search queries in your frontend app? The answer is “sometimes”, but if you think of the search query as input for the application, you will change your mind.

Jan 28, 2024

How to Choose Between Monolithic Code and Microservices

Decipher Microservices vs. Monolithic Code: Choose wisely for a seamless development journey. Plan, embrace flexibility and avoid pitfalls. Insights from a DevOps developer.

Jan 28, 2024

Website vs Web Application: Which One Do You Need?

Decipher Microservices vs. Monolithic Code: Choose wisely for a seamless development journey. Plan, embrace flexibility and avoid pitfalls. Insights from a DevOps developer.

Sep 14, 2023

A Guide to Keeping Dependencies Up-to-Date for Enhanced Security and Efficiency in Development

Learn the importance of keeping dependencies up-to-date for a secure and efficient development process...

Sep 14, 2022

No Code Pro / Contra

No-code has caused an unusual, disruptive revelation and changes in the tech space – especially coding. Are programmers and coding still relevant or not?

Aug 14, 2022

Here are Some Reasons Why You Should Become a Software Engineer

Yes, software engineering is a good job based on virtually any criteria, including salary, the number of job openings, as well as overall job satisfaction...

Jul 14, 2022

A Guide to Working Remotely at Sea: Best Practices

Putting some effort into planning will make your entire trip more enjoyable. If you’re independently setting sail, plot a course that takes your availability into account.

Jun 14, 2022

11 Essential Skills to Become a Software Developer in 2022

Key skills for programmers and software developers to learn in 2022. If you have been doing software development for some time and thinking about what makes a good programmer?

Aug 16, 2023

How to Implement Request Validation with OAPI-Codegen and Go for Robust Development

Several of our projects require back-end as well as front-end work. If a client wants us to create RESTful APIs, we start by using the OpenAPI 3 specification.

Aug 31, 2023

The Best Way to Optimize Serverless Computing

Explore the latest features of Cloud Run for seamless deployment and scaling...

Nov 16, 2023

Discover How reCAPTCHA v3 and Cloud Armor Can Protect your Website

Discover advanced bot prevention strategies using reCAPTCHA v3 and Cloud Armor. Safeguard your website with CommIT Smart's insightful guide...

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Other articles

Sep 20, 2024

Emotional Intelligence in IT Project Management

Emotional intelligence is key in IT project management. It helps leaders manage teams, resolve conflicts, and build stronger relationships, leading to more successful projects

Oct 20, 2024

Great Leaders Anticipate, Not Just React

Ready to elevate your leadership? Discover how anticipating challenges, not just reacting, can unlock success. Don't miss out on this game-changing mindset shift!...

Aug 30, 2024

How Our StemX Editors Are Revolutionizing Ticket Sales

Discover how StemX Editors are revolutionizing ticket sales with innovative design tools! See how InterTicket's new suite boosts efficiency and transforms user experiences....

AI Estimation

Let Us Provide the Perfect Solution for Your Project

Looking for accurate project estimates? Our AI-powered app helps you plan smarter. Contact us today, and we’ll provide a customized quote for your business needs — quick, reliable, and aligned with your goals.

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

Get in touch

Reach Out to Us!

Have questions or want to learn more about what we do at CommIT Smart? We’d love to hear from you! Whether you’re curious about our work or just want to start a conversation, don’t hesitate to reach out. Our team is here and ready to connect — let’s talk!

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.

We are innovators in developing most recent web technologies, blockchain, digital technologies and apps in ingenious ways.

The D&B certificate is awarded exclusively to businesses with excellent creditworthiness. Possession of the certificate guarantees that establishing a business relationship with our company carries a low financial risk.

© 2024 Commitsmart Kft. All rights reserved.