⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Kubernetes Interview Questions Scenario 154 of 207 in Kubernetes
Senior DevOps / SRE [L2] Kubernetes Additional Kubernetes Scenarios (Q101-Q200) Production Scenario [L2]

Q: How do you create a self-signed TLS certificate for an Ingress?

To create a self-signed TLS certificate for an Ingress, generate a key and certificate with openssl req -x509 including a SubjectAltName, store them as a kubernetes.io/tls Secret with kubectl create secret tls, and reference that.

#Kubernetes #L2 #Container Orchestration #K8s #Ingress
🎙️ Candidate Opening & Architectural Context
"To <strong>create a self-signed TLS certificate for an Ingress</strong>, generate a key and certificate with <code>openssl req -x509</code> including a SubjectAltName, store them as a <code>kubernetes.io/tls</code> Secret with <code>kubectl create secret tls</code>, and reference that Secret in the Ingress <code>tls</code> block. It is a good fit for dev and test clusters. Interviewers ask it to see if you know the Secret and Ingress wiring, why SAN matters, and when to switch to cert-manager."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's CKA & CKAD Hands-On Certification Track covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

Direct Answer: To <strong>create a self-signed TLS certificate for an Ingress</strong>, generate a key and certificate with <code>openssl req -x509</code> including a SubjectAltName, store them as a <code>kubernetes.io/tls</code> Secret with <code>kubectl create secret tls</code>, and reference that Secret in the Ingress <code>tls</code> block. It is a good fit for dev and test clusters. Interviewers ask it to see if you know the Secret and Ingress wiring, why SAN matters, and when to switch to cert-manager.

1️⃣

Mental model: key, certificate, Secret, Ingress

Four pieces connect, and the failure is usually in how they are linked.

  • Certificate and key: a self-signed certificate is its own issuer, so clients do not trust it unless you add it to their trust store or skip verification.
  • Secret: type kubernetes.io/tls with keys tls.crt and tls.key, in the same namespace as the Ingress.
  • Ingress: the tls section lists hostnames and secretName; the controller loads the certificate and serves it through SNI.
  • SAN requirement: modern clients ignore the Common Name and validate the SubjectAltName, so always include the DNS name there.
  • When it is appropriate: local clusters, CI environments and internal tooling where you control the clients and can distribute the certificate.
Pro Tip: Without a SAN entry, browsers and curl report a hostname mismatch even if the CN is correct.
2️⃣

Hands-on: create a self-signed TLS certificate for an Ingress

Generate the files and create the Secret.

openssl req -x509 -newkey rsa:2048 -nodes -sha256 -days 365 \
  -keyout tls.key -out tls.crt \
  -subj "/CN=app.example.com" \
  -addext "subjectAltName=DNS:app.example.com,DNS:www.example.com"

kubectl create secret tls app-example-tls \
  --cert=tls.crt --key=tls.key -n prod
kubectl -n prod get secret app-example-tls -o jsonpath='{.type}{"\n"}'
  • One command: openssl req -x509 -newkey rsa:2048 -nodes creates the key and certificate together; -days sets validity.
  • SAN via -addext: supported in OpenSSL 1.1.1 and newer. macOS ships LibreSSL by default, where -addext may not work, so use Homebrew OpenSSL or a config file.
  • Create the Secret: kubectl create secret tls app-example-tls --cert=tls.crt --key=tls.key -n prod.
  • Wildcard: use DNS:*.dev.example.com in the SAN when several hosts share the certificate.
  • Key size and algorithm: RSA 2048 is widely compatible; ECDSA keys with -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 are smaller and also supported by common controllers.
  • Keep the private key private: do not commit tls.key to Git; create the Secret from the files and delete them, or generate them in CI.
Advertisement
3️⃣

Wire the Secret into the Ingress

Host names in tls.hosts must match the rule host and the certificate.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app
  namespace: prod
spec:
  ingressClassName: nginx
  tls:
    - hosts:
        - app.example.com
      secretName: app-example-tls
  rules:
    - host: app.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: my-app
                port:
                  number: 80
  • tls block: list the hosts and secretName; the Secret must be in the Ingress namespace.
  • ingressClassName: make sure the controller you expect handles the Ingress.
  • Redirects: ingress-nginx redirects HTTP to HTTPS by default when TLS is configured; adjust via annotation if needed.
  • Rotation: to replace the cert, update the Secret in place; most controllers reload it without a restart.
  • One Secret per host group: several Ingress objects in the same namespace can reuse one Secret if the SAN covers all their hosts.
4️⃣

Verify the served certificate and troubleshoot

Check what the controller actually presents, not what you think you configured.

openssl x509 -in tls.crt -noout -subject -dates -ext subjectAltName
curl -v --resolve app.example.com:443:203.0.113.10 --cacert tls.crt https://app.example.com/
openssl s_client -connect 203.0.113.10:443 -servername app.example.com </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer
  • Inspect the file: openssl x509 -in tls.crt -noout -subject -dates -ext subjectAltName (the -ext flag needs OpenSSL 1.1.1 or newer).
  • Test without DNS: curl --resolve app.example.com:443:<ingress-ip> https://app.example.com -k -v; remove -k and add --cacert tls.crt to check proper trust.
  • SNI view: openssl s_client -connect <ingress-ip>:443 -servername app.example.com shows the presented certificate.
  • Default fake certificate: if you see the controller's 'Kubernetes Ingress Controller Fake Certificate', the Secret name, namespace, type or host does not match, and the controller log says why.
  • Controller logs: ingress-nginx logs messages such as an unexpected error loading the secret, which pinpoint a wrong type or missing keys.
  • Browser warnings: a self-signed certificate warns unless the certificate is imported as trusted, which is expected and not a cluster fault.
5️⃣

Production practice: use cert-manager or a real CA

Self-signed certificates do not scale beyond local use.

  • cert-manager SelfSigned or CA issuer: automates creation and renewal inside the cluster, with the Certificate resource producing the Secret.
  • Public hosts: use ACME with Let's Encrypt for internet-facing names.
  • Local dev trust: a tool like mkcert creates a local CA so browsers trust the certificate without warnings.
  • Expiry monitoring: alert on certificate expiry, since self-signed certs expire silently.
  • Trust distribution: for service-to-service calls, mount the CA certificate into clients through a ConfigMap instead of disabling verification.
  • Renewal drill: rehearse replacing the certificate before expiry, including updating the Secret and confirming the controller serves the new serial number.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: always include a SubjectAltName and keep the TLS Secret in the same namespace as the Ingress. If you see the controller's Fake Certificate, the Secret is not being picked up."
⚡ 60-Second Elevator Pitch Talking Points
  • I generate a key and self-signed certificate with openssl including a SAN, then create a kubernetes.io/tls Secret.
  • I reference it in the Ingress tls block and verify with openssl s_client and curl --resolve.
  • I automate with cert-manager issuers and monitor expiry instead of hand-made certificates.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Omitting the SubjectAltName from the certificate Modern clients check the SAN and reject the certificate even when the CN matches.
  2. Creating the TLS Secret in a different namespace than the Ingress The controller cannot read it and serves its default fake certificate.
  3. Using -k permanently instead of trusting the certificate It hides real problems and trains teams to ignore TLS errors.
  4. Using self-signed certificates for production traffic Clients cannot verify them and renewal is manual, which leads to outages when they expire.
Advertisement
📥 FREE DOWNLOAD · 101-PAGE COMPANION HANDBOOK
Studying for Kubernetes & SRE Technical Rounds?
Download the complete 100-question PDF field guide covering all 11 core modules with offline diagnostic runbooks.
📥 Download PDF (Free) Read Online Guide →
Want more Kubernetes scenarios?
Explore our complete collection of scenario-based Kubernetes interview runbooks.
Browse All Kubernetes Questions →