Ingress
Ingress
Routes external traffic into Kubernetes services. L7 load balancing.
Ingress
Routes external traffic into Kubernetes services. L7 load balancing.
Ingress is an API object that manages HTTP/HTTPS traffic from outside a Kubernetes cluster to internal services. Unlike a Service that simply exposes a port, Ingress provides L7 (application layer) features such as domain-based routing, TLS termination, and load balancing.
# ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app-ingress
namespace: production
annotations:
# NGINX Ingress ์ค์
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: "10m"
spec:
ingressClassName: nginx # Ingress Controller ์ง์
tls:
- hosts:
- api.example.com
- web.example.com
secretName: example-tls # TLS ์ธ์ฆ์ Secret
rules:
# ํธ์คํธ ๊ธฐ๋ฐ ๋ผ์ฐํ
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80
- host: web.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: web-service
port:
number: 80
# path-based-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: path-routing-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
ingressClassName: nginx
rules:
- host: example.com
http:
paths:
# /api/* -> api-service
- path: /api(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: api-service
port:
number: 8080
# /static/* -> static-service
- path: /static(/|$)(.*)
pathType: ImplementationSpecific
backend:
service:
name: static-service
port:
number: 80
# ๋๋จธ์ง -> frontend
- path: /
pathType: Prefix
backend:
service:
name: frontend-service
port:
number: 80
# tls-secret.yaml
apiVersion: v1
kind: Secret
metadata:
name: example-tls
namespace: production
type: kubernetes.io/tls
data:
tls.crt: LS0tLS1CRUdJTi... # base64 encoded
tls.key: LS0tLS1CRUdJTi... # base64 encoded
---
# cert-manager๋ก ์๋ ๋ฐ๊ธ (๊ถ์ฅ)
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: example-cert
namespace: production
spec:
secretName: example-tls
issuerRef:
name: letsencrypt-prod
kind: ClusterIssuer
dnsNames:
- api.example.com
- web.example.com
# advanced-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: advanced-ingress
annotations:
# Rate Limiting
nginx.ingress.kubernetes.io/limit-rps: "10"
nginx.ingress.kubernetes.io/limit-connections: "5"
# CORS
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/cors-allow-origin: "https://example.com"
nginx.ingress.kubernetes.io/cors-allow-methods: "GET, POST, PUT, DELETE"
# ํ์์์
nginx.ingress.kubernetes.io/proxy-connect-timeout: "30"
nginx.ingress.kubernetes.io/proxy-read-timeout: "300"
nginx.ingress.kubernetes.io/proxy-send-timeout: "300"
# WebSocket ์ง์
nginx.ingress.kubernetes.io/proxy-http-version: "1.1"
nginx.ingress.kubernetes.io/upstream-hash-by: "$request_uri"
# ์ปค์คํ
ํค๋
nginx.ingress.kubernetes.io/configuration-snippet: |
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
# Basic Auth
nginx.ingress.kubernetes.io/auth-type: basic
nginx.ingress.kubernetes.io/auth-secret: basic-auth
nginx.ingress.kubernetes.io/auth-realm: "Authentication Required"
spec:
ingressClassName: nginx
rules:
- host: admin.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: admin-service
port:
number: 80
# aws-alb-ingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: aws-alb-ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:...
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS": 443}]'
alb.ingress.kubernetes.io/ssl-redirect: "443"
alb.ingress.kubernetes.io/healthcheck-path: /health
alb.ingress.kubernetes.io/success-codes: "200,301"
spec:
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80
Creating an Ingress resource alone will not work. You must install an Ingress Controller such as NGINX or Traefik first.
Annotations differ for each Ingress Controller. Annotations for NGINX Ingress do not work with Traefik.
Choose the correct type among Prefix, Exact, and ImplementationSpecific. With Prefix, /api matches both /api and /api/users.
A TLS Secret must be in the same namespace as the Ingress. You cannot reference a Secret in a different namespace.