brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Apr 17. 2023

7. nhn클라우드- nks-guestbook


<0> 방명록 서비스 네임 스페이스 생성

<1> Service + Redis(Leader)

<2> Service + Redis(Follower) 2pods

<3> 방명록 프론트엔드 파드(웹) 생성 

<4> 외부에서 접속

<5> (옵션) 방명록 프론트엔드 디플로이먼트 갯수 6개 증가, 1개 축소 등 후 글 써보고 확인 

<6> 정리



<0> 방명록 서비스 네임 스페이스 생성


1

https://kubernetes.io/ko/docs/tutorials/stateless-application/guestbook/


2

구성 ?

외부 클라이언트 ------- 클래식 로드 밸런서 ----- 레디스-------- 파드


3

kubectl create namespace guestbook

k ns guestbook



<1> Service + Redis(Leader)


1

# Redis 리더 파드 생성(TCP 6379)


kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/ko/examples/application/guestbook/redis-leader-deployment.yaml


# Redis 리더 서비스 생성(TCP 6379) : 프런트애플리케이션에서 데이터 접근 하기 위함

kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/ko/examples/application/guestbook/redis-leader-service.yaml



<2> Service + Redis(Follower) 2pods


# Redis 팔로워 파드 생성(TCP 6379)


kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/ko/examples/application/guestbook/redis-follower-deployment.yaml


# 리더와 동기화 성공 로그 확인!

kubectl logs -f deployment/redis-follower


3

# Redis 팔로워 서비스 생성(TCP 6379) : 프런트애플리케이션에서 데이터 읽기 접근 하기 위함(부하분산)


kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/ko/examples/application/guestbook/redis-follower-service.yaml




<3> 방명록 프론트엔드 파드(웹) 생성 


1

PHP(DB 읽기 시 follower redis service 로 전달, 쓰기 시 leader redis service 로 전달), JSON 인터페이스 노출, jQuery-Ajax 기반 UX


kubectl apply -f https://raw.githubusercontent.com/kubernetes/website/main/content/ko/examples/application/guestbook/frontend-deployment.yaml



// 아래  frontend 서비스 생성 하지 않고 , 클래식 로드 밸런서 바로 생성 해서 해보자.


cat <<EOF | kubectl create -f -

apiVersion: v1

kind: Service

metadata:

  name: frontend

  labels:

    app: guestbook

    tier: frontend

spec:

  ports:

  - port: 80

  selector:

    app: guestbook

    tier: frontend

  type: NodePort

EOF


type: NodePort  => LoadBalancer  로 변경





<4> 외부에서 접속


1

k delete service frontend

kubectl expose deployment frontend --port=80 --type=LoadBalancer


또는

type: NodePort  => LoadBalancer  로 변경




2

Every 2.0s: kubectl get all                                                                                                                                                                      Mon Apr 17 19:20:01 2023


NAME                                  READY   STATUS    RESTARTS   AGE

pod/frontend-767747dfdd-9j4gn         1/1     Running   0          6m24s

pod/frontend-767747dfdd-lbqz9         1/1     Running   0          6m24s

pod/frontend-767747dfdd-lvgd2         1/1     Running   0          6m24s

pod/redis-follower-86546888fd-hszz8   1/1     Running   0          7m

pod/redis-follower-86546888fd-ssmfd   1/1     Running   0          7m

pod/redis-leader-55b556899d-npr6q     1/1     Running   0          7m38s


NAME                     TYPE           CLUSTER-IP       EXTERNAL-IP      PORT(S)        AGE

service/frontend         LoadBalancer   10.254.105.147   133.186.203.22   80:31851/TCP   4m19s

service/redis-follower   ClusterIP      10.254.51.248    <none>           6379/TCP       6m35s

service/redis-leader     ClusterIP      10.254.129.17    <none>           6379/TCP       7m17s


NAME                             READY   UP-TO-DATE   AVAILABLE   AGE

deployment.apps/frontend         3/3     3            3           6m24s

deployment.apps/redis-follower   2/2     2            2           7m

deployment.apps/redis-leader     1/1     1            1           7m38s


NAME                                        DESIRED   CURRENT   READY   AGE

replicaset.apps/frontend-767747dfdd         3         3         3       6m24s

replicaset.apps/redis-follower-86546888fd   2         2         2       7m

replicaset.apps/redis-leader-55b556899d     1         1         1       7m38s



3


4

삭제

kubectl delete deploy,svc frontend redis-follower redis-leader



<5> (옵션) 방명록 프론트엔드 디플로이먼트 갯수 6개 증가, 1개 축소 등 후 글 써보고 확인 

→ 데이터를 Redis 에 쓰고 가져오기 때문에 문제 없음



<6> 정리


type: NodePort  => LoadBalancer  로 변경

외부에서 접속 가능

동작함



감사합니다.

매거진의 이전글 6. nhn클라우드- nks-은행 계좌 조회

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari