متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 132Kubernetes · Network

How to expose an app with an Ingress and TLS

Your app runs in Kubernetes as a Service — now users must reach https://shop.example.com. That is the job of an Ingress (or its successor, the Gateway API): host and path rules to Services, with a TLS certificate that cert-manager gets and renews automatically. Note: the popular ingress-nginx controller was retired in March 2026 — new clusters should use the Gateway API or another maintained controller. This how-to shows both ways.

  • 5 الدروس
  • 5 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

132.1

The quick answer

Gateway API (new clusters, with a controller such as Envoy Gateway installed):

httproute.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: shop
  namespace: shop
spec:
  parentRefs:
    - name: public-gw
      namespace: gateway
  hostnames: ["shop.example.com"]
  rules:
    - backendRefs:
        - name: frontend
          port: 80
kubectl apply -f httproute.yaml
kubectl get httproute -n shop
curl -sI https://shop.example.com | head -1

132.2

Step by step

  1. Check what the cluster has — a controller is needed, the YAML alone does nothing:
kubectl get gatewayclass
kubectl get ingressclass
  1. Gateway API — the platform team's Gateway (listeners and TLS), shared by many apps:
gateway.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: public-gw
  namespace: gateway
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  gatewayClassName: eg
  listeners:
    - name: https-shop
      protocol: HTTPS
      port: 443
      hostname: shop.example.com
      tls:
        certificateRefs:
          - name: shop-tls
      allowedRoutes:
        namespaces: { from: All }

cert-manager sees the annotation and creates the shop-tls certificate (its Gateway API support must be enabled). The app team only writes the HTTPRoute (quick answer).

  1. Ingress — the classic way (clusters with a maintained Ingress controller, for example Traefik):
ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: shop
  namespace: shop
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-prod
spec:
  ingressClassName: traefik
  tls:
    - hosts: ["shop.example.com"]
      secretName: shop-tls
  rules:
    - host: shop.example.com
      http:
        paths:
          - path: /
            pathType: Prefix
            backend:
              service:
                name: frontend
                port:
                  number: 80
  1. DNS — point shop.example.com to the load balancer of the Gateway/Ingress controller:
kubectl get svc -n gateway
dig +short shop.example.com
  1. Watch the certificate:
kubectl get certificate -A
kubectl describe certificate shop-tls -n gateway

READY True = issued; otherwise the events show the ACME challenge step that fails.

132.3

Check that it worked

curl -sI https://shop.example.com returns 200/301 with a valid certificate (issuer Let's Encrypt), and kubectl get certificate shows READY True with a renewal date.

132.4

Common problems

ProblemCauseFix
Nothing happens after applyNo controller for that class.kubectl get gatewayclass/ingressclass; install a controller; set the right class name.
404 from the controllerHost or path does not match.Check hostnames/host and the path type; test with curl -H 'Host: …'.
503 / no endpointsService name/port wrong, or Pods not ready.kubectl get endpoints frontend -n shop.
Certificate stays READY FalseDNS not pointing to the controller, port 80 blocked, wrong issuer.kubectl describe certificate/order/challenge; fix DNS.
HTTPRoute not attachedGateway's allowedRoutes does not allow the namespace.Allow it, or reference the right listener.
Still on ingress-nginxRetired, no security fixes since March 2026.Plan the move to Gateway API (see the full guide).

132.5

Go further

1Why should a new cluster not use ingress-nginx?

It was retired; maintenance and security fixes ended in March 2026 — use the Gateway API or another maintained controller.

2What makes cert-manager create a certificate for an Ingress or Gateway?

The annotation cert-manager.io/cluster-issuer: NAME plus the TLS secret name in the object.

كل الأوامر في هذا الفصل