TLS مع Ingress و cert-manager
الهدف من الدرس
Section titled “الهدف من الدرس”ستفهم كيف يربط Ingress بين host و Secret يحتوي certificate، وكيف يستخدم cert-manager Issuer أو ClusterIssuer لإدارة TLS.
الفكرة ببساطة
Section titled “الفكرة ببساطة”TLS في Ingress يحتاج Secret من نوع kubernetes.io/tls. cert-manager يستطيع إنشاء هذا Secret وتجديده تلقائيا من جهة إصدار مثل Let’s Encrypt.
Certificate flow
Section titled “Certificate flow”flowchart LR I[Ingress] --> C[Certificate] C --> CI[ClusterIssuer] CI --> CA[Certificate Authority] C --> S[TLS Secret] S --> IC[Ingress Controller]YAML مختصر
Section titled “YAML مختصر”cluster-issuer.yaml:
apiVersion: cert-manager.io/v1kind: ClusterIssuermetadata: name: letsencrypt-prodspec: acme: server: https://acme-v02.api.letsencrypt.org/directory email: admin@example.com privateKeySecretRef: name: letsencrypt-prod solvers: - http01: ingress: class: nginxingress-tls.yaml:
apiVersion: networking.k8s.io/v1kind: Ingressmetadata: name: web annotations: cert-manager.io/cluster-issuer: letsencrypt-prodspec: ingressClassName: nginx tls: - hosts: - web.example.com secretName: web-tls rules: - host: web.example.com http: paths: - path: / pathType: Prefix backend: service: name: web port: name: httpأوامر الفحص
Section titled “أوامر الفحص”kubectl apply -f cluster-issuer.yamlkubectl apply -f ingress-tls.yamlkubectl get certificatekubectl describe certificate web-tlskubectl get secret web-tlsExpected output:
NAME READY SECRET AGEweb-tls True web-tls 2mLab: فحص TLS readiness
الهدف: قراءة Certificate و Secret وتشخيص سبب فشل الإصدار.
Prerequisites
Section titled “Prerequisites”- cert-manager مثبت.
- DNS حقيقي يشير إلى Ingress Controller إذا كنت ستستخدم Let’s Encrypt فعليا.
kubectl get clusterissuerkubectl get certificatekubectl describe certificate web-tlskubectl get challenges,ordersExpected output
Section titled “Expected output”Status: Conditions: Type: Ready Status: TrueCleanup
Section titled “Cleanup”kubectl delete -f ingress-tls.yamlkubectl delete -f cluster-issuer.yamlأخطاء شائعة
Section titled “أخطاء شائعة”| المشكلة | السبب |
|---|---|
| Certificate لا يصبح Ready | DNS لا يشير إلى Ingress أو challenge يفشل |
| Secret غير موجود | cert-manager لم يصدر الشهادة بعد |
| mixed content في browser | التطبيق يستخدم روابط HTTP داخل صفحة HTTPS |