ITFragile
[Kubernetes] 04. Deployment로 web server 인그레스 구성 본문
구성목표
1. web 배포 방식 : Deployment 디플로이먼트
2. 서비스 : Ingress 설정
- 외부에서 내부 파드로 접속시 포워딩 해주는 로드밸런서 기능
- 인그레스의 URL 주소로 접속하여 서비스를 통해 파드로 전달되도록 설정
3. 볼륨 : 컨피그맵을 볼륨으로 사용
- index.html , index.php 작성 후 컨피그맵 생성하여 볼륨으로 마운트
4. 오토스케일링 : HPA 구성
- 불필요한 리소스 낭비를 줄이고 파드 개수를 리소스 사용량을 기준으로 자동으로 관리하기 위해 사용
1. Ingress 설정
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ing
spec:
rules:
- host: web.kyungeun.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: svc-1
port:
number: 80
2. Service 설정
인그레스와 서비스 이름으로 연결. 디폴트는 내부 접속만 가능하므로 외부 접속을 위해 인그레스와 연결해 사용함
apiVersion: v1
kind: Service
metadata:
name: svc-1
spec:
selector:
app: myweb
ports:
- port: 80
targetPort: 80
3. Configmap 생성
볼륨형식으로 컨테이너에 연결해서 파일로 컨테이너에 제공
[index.php]
[index.html]
해당 두 파일을 컨피그맵으로 각각 생성한다.
kubectl create cm --from-file index.html cmfile # php 파일 연결
kubectl create cm --from-file index.html cmfile2 # html 파일 연결
4. Deployment 생성
# kubectl apply -f dep-web.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myweb
spec:
selector:
matchLabels:
app: myweb
replicas: 2
template:
metadata:
labels:
app: myweb
spec:
affinity:
podAntiAffinity: # 안티어피티니 설정을 통해 파드를 노드별로 분산
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchLabels:
app: web
topologyKey: "kubernetes.io/hostname"
containers:
- name: webserver
image: docker.io/kyungyyyo/mywebphp:v1
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts: # 볼륨 마운트
- name: cm-vol
mountPath: /var/www/html/index.php
subPath: index.php
- name: cm-vol2
mountPath: /var/www/html/index.html
subPath: index.html
volumes:
- name: cm-vol
configMap:
name: cmfile # 생성한 컨피그맵 연결
- name: cm-vol2
configMap:
name: cmfile2 # # 생성한 컨피그맵 연결
5. 파드 접속하여 확인
kubectl exec myweb-5f646bf7c5-glwbm -it -- bash
'Project' 카테고리의 다른 글
[Kubernetes] 06. Web server HPA 구성 (0) | 2023.03.22 |
---|---|
[Kubernetes] 05. Web-DB 연결을 위한 컨피그맵 수정 (0) | 2023.03.22 |
[Kubernetes] 03. Docker image build하기 (0) | 2023.03.21 |
[Kubernetes] 02. DB StatefulSet으로 이중화 구성 (0) | 2023.03.21 |
[Kubernetes] 01. 작업 환경 구성 (0) | 2023.03.20 |