선택사항입니다(Match ALB 확인하기). Node에 label 추가시키기(WorkerNode 1에 할당해야합니다. ASG를 통해 구분하거나, Instance Name을 통해 구분하도록 합니다.(https://ikcoo.tistory.com/89 - affinity)
#추가
kubectl label nodes ip-10-0-0-171.ap-northeast-2.compute.internal worker2=backend
kubectl label nodes ip-10-0-1-137.ap-northeast-2.compute.internal worker2=backend
#삭제
kubectl label node worker-2.example.com worker2-
kubectl create namespace wsi-skills-namespace-2
Key: Value가 있는 특정 WorkerNode에 Pod 배포 → Deployment(object) Pod 배포
cat << EOF > backdeployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-deployment
namespace: wsi-skills-namespace-2
labels:
app: backend-deployment
spec:
replicas: 2
selector:
matchLabels:
app: backend-deployment
template:
metadata:
labels:
app: backend-deployment
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: worker2 #Node Key
operator: In
values:
- backend #Node Value
containers:
- name: backend-dockerimages
image: [[DockerImage]]
ports:
- containerPort: 8080
EOF
kubectl apply -f backdeployment.yaml
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에 세부 사항을 확인할 수 있습니다.
위에서 생성한 Deployment Object Pod를 Service에 연결합니다.
cat << EOF > backservice.yaml
apiVersion: v1
kind: Service
metadata:
name: wsi-stress-service
labels:
app: backend-deployment
namespace: wsi-skills-namespace-2
annotations:
alb.ingress.kubernetes.io/healthcheck-path: "/worldskills"
spec:
selector:
app: backend-deployment
type: NodePort
ports:
- port: 8080
targetPort: 80
protocol: TCP
EOF
kubectl apply -f backservice.yaml
위에서 생성한 Service를 Ingress에 연결해서 ALB를 생성합니다.
cat << EOF > backingress.yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: "wsi-stress-ingress"
namespace: wsi-skills-namespace-2
annotations:
alb.ingress.kubernetes.io/load-balancer-name: wsi-stress-alb
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internal
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]' #이 부분은 즉, ALB에 보안그룹에도 관련이있다.
spec:
rules:
- http:
paths:
- path: /worldskills
pathType: Prefix
backend:
service:
name: "wsi-stress-service"
port:
number: 8080 #무조건 서비스 포트랑 같아야한다. 다르면 ALB 생성 조차가 안된다
EOF
kubectl apply -f backingress.yaml