k3s에 Traefik Ingress Controller 사용하여 아주 간단한 'hello world' HTTP 배포하기
- 기본적으로 k3s master node가 구성되어있는 상태여야함
Ingress 기본 개념
- HTTP, HTTPS 등 네트워크 Layer 7에 대한 설정을 담당하는 리소스
- Ingress의 가장 기본적인 역할은 외부 HTTP 호출에 대한 트래픽을 처리
- Ingress는 쿠버네티스 클러스터 내부 서비스에 외부에서 접근 가능한 URL을 부여함으로써 일반 사용자들이 쉽게 접근할 수 있는 통로를 제공
- Ingress에는 그에 맞는 Ingress Controller가 존재하며 Ingress Controller는 Ingress에 정의된 트래픽 라우팅 규칙을 보고 라우팅을 수행
- Ingress는 임의의 포트나 프로토콜을 노출하지 않음. HTTP 및 HTTPS 이외의 서비스를 인터넷에 노출하는 것은 일반적으로 Service의 Type이 NodePort이거나 LoadBalancer 유형인 경우 가능!
Ingress Controller란?
- 실제로 Ingress의 규칙을 읽고 외부의 트래픽을 Service로 전달하는 주체
- Ingress Controller는 쿠버네티스 내장 컨트롤러와는 다르게 명시적으로 컨트롤러를 설치해야함
- Ingress Controller 종류
- NGINX Ingress Controller
- HAProxy
- AWS ALB Ingress Controller
- Ambassador
- Kong
- traefik
* 이 포스팅에서는 traefik Ingress Controller를 이용할 예정
ConfigMap으로 저장할 HTML 파일 생성 : index.html
# index.html 내용
<html>
<head>
<title>Hello World!</title>
</head>
<body>Hello World!</body>
</html>
index.html파일로 configmap 생성
- configmap 리소스는 메타데이터(설정값)를 저장하는 리소스
kubectl create configmap [key] --from-file [data-source]
- 생성된 ConfigMap 상세 조회
kubectl get cm <key> -o yaml
kubernetes 리소스 정의 yml 파일 작성
# hello-world.yml 내용
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: hello-world
annotations:
kubernetes.io/ingress.class: "traefik"
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: hello-world
port:
number: 80
---
apiVersion: v1
kind: Service
metadata:
name: hello-world
spec:
ports:
- port: 80
protocol: TCP
selector:
app: hello-world
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-world-nginx
spec:
selector:
matchLabels:
app: hello-world
replicas: 3
template:
metadata:
labels:
app: hello-world
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
volumeMounts:
- name: hello-world-volume
mountPath: /usr/share/nginx/html
volumes:
- name: hello-world-volume
configMap:
name: hello-world
# kind: Ingress 에 대한 설명
- annotations : 메타 정보를 저장하기 위한 property / Ingress에서는 Ingress Controller에게 메타정보를 전달할 목적으로 사용
- rules : 외부 트래픽을 어떻게 처리할지 정의
- rules[0].host : 특정 도메인으로 들어오는 트래픽에 대해 라우팅을 정의하며, 예시 yml파일처럼 만약 생략되어 있는 경우 모든 호스트 트래픽(*)을 처리
- rules[0].http.paths[0].path : Ingress path를 정의
- rules[0].http.paths[0].backend : Ingress의 트래픽을 받을 Service와 포트를 정의
Nginx 컨테이너, 서비스 및 Traefik Ingress 리소스 배포
kubectl apply -f hello-world.yml
Ingress 생성 후 자세한 정보 확인
kubectl describe ingress ingress-resource-backend
80 포트를 통해 접근
curl localhost:80
k3s 대시보드를 통해 확인
# POD 확인
# 인그레스
# configmap
Traefik Ingress Controller 참조 DOC
https://doc.traefik.io/traefik/providers/kubernetes-ingress/
Traefik Kubernetes Ingress Documentation - Traefik
Traefik & Kubernetes The Kubernetes Ingress Controller. The Traefik Kubernetes Ingress provider is a Kubernetes Ingress controller; that is to say, it manages access to cluster services by supporting the Ingress specification. Requirements Traefik supports
doc.traefik.io
'컨테이너 > Kubernetes' 카테고리의 다른 글
Kubernetes Terminated 상태의 pod 삭제 / Pods stuck in Terminating status / 503 Service Unavailable (0) | 2022.11.23 |
---|---|
Kubernetes(k3s) Pod / Service / Namespace 관련 기본 명령어 학습 (0) | 2022.11.02 |
k3s 워커노드 설치하고 k3s 대시보드 확인하기 (0) | 2022.10.31 |
k3s dashboard 설치 및 원격 허용 설정(Node Port방식) (0) | 2022.10.31 |
ubuntu에 k3s 마스터 노드 설치 쉽고 간단하게 (0) | 2022.10.28 |