반응형
선택사항입니다. 이미 CLI로 생성할 떄 추가 해줬기 때문에 굳이 안해도 되지만, Label 추가 방법은 소개드리고 싶어서 아래 명령을 작성합니다.(https://ikcoo.tistory.com/89 - affinity)
kubectl label nodes ip-10-0-0-171.ap-northeast-2.compute.internal worker1=front
kubectl label nodes ip-10-0-1-137.ap-northeast-2.compute.internal worker1=front
Namespace Create
kubectl create namespace wsi-skills-namespace
Deployment Object Create
1. Key: Value가 있는 특정 WorkerNode에 Pod 배포 → Deployment(object) Pod 배포
cat << EOF > frontdeployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: front-deployment
namespace: wsi-skills-namespace
labels:
app: front-deployment
spec:
replicas: 2
selector:
matchLabels:
app: front-deployment
template:
metadata:
labels:
app: front-deployment
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: worker1 #Node Key #Label에 Key 입니다.
operator: In
values:
- front #Node Value #Label에 Value입니다
containers:
- name: wsi-skills-container #Container Name
image: [[DockerImage]]
ports:
- containerPort: 80 #Container Image Port
EOF
kubectl apply -f frontdeployment.yaml
2. Deployment Object가 즉, Pod가 정상적으로 실행중인지 아래 명령어로 확인합니다.
kubectl get pods -n wsi-skills-namespace
kubectl get pods -o wide -n wsi-skills-namespace #현재 어떤 노드에 실행중인지 확인
kubectl logs [PodName] -n wsi-skills-namespace #Pod에 Log를 확인할 수 있습니다.
kubectl describe pods [PodName] -n wsi-skills-namespace #Pod에 세부 사항을 확인할 수 있습니다.
Service 배포!!
1. 위에서 생성한 Deployment Object Pod를 Service에 연결합니다.
cat << EOF > frontservice.yaml
apiVersion: v1
kind: Service
metadata:
name: wsi-match-service
labels:
app: front-deployment
namespace: wsi-skills-namespace
annotations:
alb.ingress.kubernetes.io/healthcheck-path: "/healthcheck path" #대상그룹에 HealthCheck 경로입니다.
spec:
selector:
app: front-deployment #selector를 사용해서 Label이 매치되는 Pod를 Service와 연결합니다.
type: NodePort
ports:
- port: 80 #Service Port를 설정합니다.
targetPort: 8080 #TargetGroup Port
protocol: TCP #Protocol 설정
EOF
kubectl apply -f frontservice.yaml
Ingress 배포 > 즉, ALB Ingree Create
1. 위에서 생성한 Service를 Ingress에 연결해서 ALB를 생성합니다.
cat << EOF > frontingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: "wsi-match-ingress"
namespace: wsi-skills-namespace
annotations:
alb.ingress.kubernetes.io/load-balancer-name: wsi-match-alb #ALB Name
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing #외부 Schema
alb.ingress.kubernetes.io/target-type: ip #Ip 즉, Pod를 TargetGroup에 연결
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]' #리스너 설정, 이 부분은 즉, ALB에 보안그룹에도 관련이있다.
spec:
rules:
- http:
paths:
- path: /healthcheckPath #Service HealthCheck 경로
pathType: Prefix
backend:
service:
name: "wsi-match-service"
port:
number: 80 #전 단계에서 생성한 서비스 포트입니다. 다르게 설정하면 생성되지 않습니다.
EOF
kubectl apply -f frontingress.yaml
반응형
'2022년 전에 정리한 문서들' 카테고리의 다른 글
EKS - Horizontal Pod Autoscaling(CPU) - Pod (0) | 2022.08.24 |
---|---|
EKS - Internal ALB Node Objects(Backend) - 1.22 Version (0) | 2022.08.24 |
EKS - ALB Controller Create (0) | 2022.08.24 |
EKS - Cluster and Nodegroups Create (CLI) (0) | 2022.08.24 |
EKS - Cluster and Nodegroups Create (CLI) (0) | 2022.08.24 |