TLS終端とHTTPSによるIngressの保護
IngressでTLSを設定し、証明書をSecretとして保存し、cert-managerで発行を自動化して、HTTPSでトラフィックを提供します。
「TLS終端とHTTPSによるIngressの保護」はCoddyKit上の無料Docker & Kubernetes for Developersレッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはDocker & Kubernetes for Developers学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Docker & Kubernetes for Developersコースには全4レッスンが含まれています。
このレッスンの一部はまだ翻訳されておらず、英語で表示されています。
Why TLS at the Ingress
Terminating TLS at the Ingress lets one place handle HTTPS for many backend services, so internal apps can stay plain HTTP while users get encryption.
Certificates Live in Secrets
An Ingress references a TLS certificate stored in a Kubernetes Secret of type kubernetes.io/tls, holding a tls.crt and tls.key.
kubectl create secret tls my-tls \
--cert=tls.crt --key=tls.keyAdding a tls Block to Ingress
The spec.tls section maps hostnames to the secret that secures them.
spec:
tls:
- hosts:
- app.example.com
secretName: my-tls
rules:
- host: app.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web
port:
number: 80How Termination Works
The Ingress controller decrypts incoming HTTPS, then forwards plain HTTP to the backend Service inside the cluster network.
The Certificate Renewal Problem
Certificates expire. Renewing and re-uploading them by hand is error prone, which is why automation tools exist.
Introducing cert-manager
cert-manager is an add-on that watches Ingress/Certificate resources and automatically obtains and renews certificates from issuers like Let us Encrypt.
Defining a ClusterIssuer
A ClusterIssuer tells cert-manager how to get certificates cluster-wide.
apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
name: letsencrypt-prod
spec:
acme:
server: https://acme-v02.api.letsencrypt.org/directory
email: admin@example.com
privateKeySecretRef:
name: letsencrypt-prod
solvers:
- http01:
ingress:
class: nginxAnnotating the Ingress
Add an annotation so cert-manager issues a cert and stores it in the named secret automatically.
metadata:
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prodHTTP-01 vs DNS-01
HTTP-01 proves domain ownership by serving a token over HTTP; DNS-01 proves it via a DNS TXT record and supports wildcard certificates.
Forcing HTTPS Redirects
Most controllers redirect HTTP to HTTPS by default. With NGINX you can control it via an annotation.
metadata:
annotations:
nginx.ingress.kubernetes.io/force-ssl-redirect: "true"Verifying the Certificate
Check the Certificate resource and inspect the served cert.
kubectl get certificate
openssl s_client -connect app.example.com:443Quick Check
Test what you have learned.
Recap
You learned to terminate TLS at the Ingress using a tls Secret, automate issuance and renewal with cert-manager and a ClusterIssuer, choose HTTP-01 vs DNS-01, and force HTTPS redirects.
よくある質問
「TLS終端とHTTPSによるIngressの保護」レッスンは無料ですか?
はい。「TLS終端とHTTPSによるIngressの保護」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Docker & Kubernetes for Developersコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Docker & Kubernetes for Developersコースには全4レッスンが含まれています。
「TLS終端とHTTPSによるIngressの保護」で何を学びますか?
IngressでTLSを設定し、証明書をSecretとして保存し、cert-managerで発行を自動化して、HTTPSでトラフィックを提供します。 ブラウザで直接実行するハンズオンコードでDocker & Kubernetes for Developersを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Docker & Kubernetes for Developersを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのDocker & Kubernetes for Developersは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。
「TLS終端とHTTPSによるIngressの保護」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このDocker & Kubernetes for Developersレッスンでコードを書いて実行できますか?
はい。すべてのDocker & Kubernetes for Developersレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- Kubernetes Ingressとルーティング
- ネットワークポリシーの実装
- K8sのサービスディスカバリとDNS
- TLS終端とHTTPSによるIngressの保護