Kubernetes Ingress 및 라우팅
Ingress 리소스를 구성하여 서비스에 대한 외부 접근을 제공하고 고급 라우팅과 TLS 종료를 구현합니다.
Kubernetes Ingress 및 라우팅은(는) CoddyKit의 무료 Docker & Kubernetes for Developers 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Docker & Kubernetes for Developers 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Get External Access with Ingress
So far, we've used Services like NodePort or LoadBalancer to expose our applications outside the Kubernetes cluster.
While effective, these have limitations for complex routing, host-based rules, or managing TLS certificates for multiple applications.
This is where Ingress comes in! It acts as an entry point for external traffic, offering more advanced routing capabilities.
Ingress vs. Services: Key Differences
Let's clarify the roles:
- Service: Provides stable networking for Pods within the cluster and can expose a single application externally (e.g.,
NodePort,LoadBalancer). - Ingress: Manages external access to multiple Services, offering features like URL routing, host-based routing, and SSL/TLS termination.
Think of Ingress as a smart traffic controller for your external requests.
The Brain: Ingress Controller
An Ingress resource itself doesn't do anything on its own. It's just a set of rules you define.
You need an Ingress Controller running in your cluster. This controller watches for Ingress resources and configures a proxy (like Nginx, HAProxy, or Traefik) to fulfill those rules.
Without an Ingress Controller, your Ingress rules are ignored!
Anatomy of an Ingress Rule
An Ingress resource uses YAML to define how traffic should be routed. Here's a basic structure:
It specifies rules based on hostnames and paths, directing traffic to a specific Kubernetes Service.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-app-ingress
spec:
rules:
- host: myapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-app-service
port:
number: 80Routing by Hostname
One powerful feature is host-based routing. You can direct traffic for different hostnames to different backend Services.
For example, blog.example.com goes to your blog service, and api.example.com goes to your API service.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: multi-host-ingress
spec:
rules:
- host: blog.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: blog-service
port:
number: 80
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80Routing by URL Path
You can also route traffic based on the URL path. This is useful for exposing different parts of a single application or microservices under one domain.
For instance, myapp.com/users might go to a user service, while myapp.com/products goes to a product service.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: path-ingress
spec:
rules:
- host: myapp.example.com
http:
paths:
- path: /users
pathType: Prefix
backend:
service:
name: user-service
port:
number: 80
- path: /products
pathType: Prefix
backend:
service:
name: product-service
port:
number: 80Handling Unmatched Requests
What if no host or path rule matches an incoming request?
You can define a default backend in your Ingress. This directs all unmatched traffic to a specific Service, often a simple "404 Not Found" page or a default landing page.
It's good practice to always include a default backend for robustness.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: default-backend-ingress
spec:
defaultBackend:
service:
name: default-404-service
port:
number: 80
rules:
- host: myapp.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80Secure Traffic with TLS
Security is crucial! Ingress can also handle TLS termination. This means the Ingress Controller decrypts incoming HTTPS traffic before forwarding it to your backend Services (which can then run on plain HTTP).
This offloads SSL/TLS certificate management from your application Pods to the Ingress Controller.
You'll need a Kubernetes Secret containing your TLS certificate and key.
Ingress with TLS Example
To enable TLS, you reference a Kubernetes Secret in your Ingress definition. This Secret must contain the TLS certificate and private key.
The Ingress Controller will then use this certificate for HTTPS connections to your domain.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: secure-app-ingress
spec:
tls:
- hosts:
- secureapp.example.com
secretName: secureapp-tls-secret # Refers to a Kubernetes Secret
rules:
- host: secureapp.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: secure-app-service
port:
number: 443 # Or 80, if backend is HTTPIngress Routing Check
Consider an Ingress resource with the following rule:
rules:
- host: myapp.example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 80
- path: /
pathType: Prefix
backend:
service:
name: frontend-service
port:
number: 80
Which service will a request to http://myapp.example.com/api/v1/users be routed to?
Ingress: Your Smart Traffic Cop
In this lesson, you've learned about Kubernetes Ingress, a powerful tool for managing external access to your cluster.
- Ingress provides advanced routing features like host and path-based rules.
- An Ingress Controller is essential to make Ingress rules work.
- You can easily secure your applications with TLS termination using Ingress and Kubernetes Secrets.
Ingress simplifies exposing complex applications and microservices to the outside world!
자주 묻는 질문
“Kubernetes Ingress 및 라우팅” 강의는 무료인가요?
네 — “Kubernetes Ingress 및 라우팅” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Docker & Kubernetes for Developers 강의 전체를 잠금 해제할 수 있습니다. Docker & Kubernetes for Developers 강의에는 총 4개의 강의가 포함되어 있습니다.
“Kubernetes Ingress 및 라우팅”에서 뭘 배우나요?
Ingress 리소스를 구성하여 서비스에 대한 외부 접근을 제공하고 고급 라우팅과 TLS 종료를 구현합니다. 브라우저에서 직접 실행하는 실습 코드로 Docker & Kubernetes for Developers을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Docker & Kubernetes for Developers을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Docker & Kubernetes for Developers은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“Kubernetes Ingress 및 라우팅” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Docker & Kubernetes for Developers 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Docker & Kubernetes for Developers 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Kubernetes Ingress 및 라우팅
- 네트워크 정책 구현
- K8s 서비스 검색 및 DNS
- TLS 종료 및 HTTPS로 Ingress 보호하기