-
Kubernetes 실습 - Voting Appkubernetes 2021. 12. 27. 21:06
아래 구조의 서비스를 kubernetes 로 구성해 보자
참고: https://github.com/mmumshad/kubernetes-example-voting-app
Pod(voting-app, result-app, redis, db, worker) yml 작성
voting-app-pod.yml
더보기apiVersion: v1 kind: Pod metadata: name: voting-app-pod labels: name: voting-app-pod app: demo-voting-app spec: containers: - name: voting-app image: dockersamples/examplevotingapp_vote ports: - containerPort: 80
result-app-pod.yml
더보기apiVersion: v1 kind: Pod metadata: name: result-app-pod labels: name: result-app-pod app: demo-voting-app spec: containers: - name: result-app image: dockersamples/examplevotingapp_result ports: - containerPort: 80
redis-pod.yml
더보기apiVersion: v1 kind: Pod metadata: name: redis-pod labels: name: redis-pod app: demo-voting-app spec: containers: - name: redis image: redis:latest ports: - containerPort: 6379
postgres-pod.yml
더보기apiVersion: v1 kind: Pod metadata: name: postgres-pod labels: name: postgres-pod app: demo-voting-app spec: containers: - name: postgres image: postgres:9.4 env: - name: POSTGRES_USER value: "postgres" - name: POSTGRES_PASSWORD value: "postgres" - name: POSTGRES_HOST_AUTH_METHOD value: trust ports: - containerPort: 5432
worker-app-pod.yml
더보기apiVersion: v1 kind: Pod metadata: name: worker-app-pod labels: name: worker-app-pod app: demo-voting-app spec: containers: - name: worker-app image: dockersamples/examplevotingapp_worker
Service(voting-app, result-app, redis, postgres) yml 작성
voting-app-service.yml
더보기apiVersion: v1 kind: Service metadata: name: voting-service labels: name: voting-service app: demo-voting-app spec: type: NodePort ports: - port: 80 targetPort: 80 nodePort: 30004 selector: name: voting-app-pod app: demo-voting-app
result-app-service.yml
더보기apiVersion: v1 kind: Service metadata: name: result-service labels: name: result-service app: demo-result-app spec: type: NodePort ports: - port: 80 targetPort: 80 nodePort: 30005 selector: name: result-app-pod app: demo-voting-app
redis-service.yml
더보기apiVersion: v1 kind: Service metadata: name: redis labels: name: redis-service app: demo-voting-app spec: ports: - port: 6379 name: redis-something targetPort: 6379 selector: name: redis-pod app: demo-voting-app
postgres-service.yml
더보기apiVersion: v1 kind: Service metadata: name: db labels: name: db-service app: demo-voting-app spec: ports: - port: 5432 targetPort: 5432 selector: name: postgres-pod app: demo-voting-app
Pod, Service 실행하기
kubectl apply -f voting-app-pod.yml kubectl apply -f voting-app-service.yml kubectl apply -f redis-pod.yml kubectl apply -f redis-service.yml kubectl apply -f postgres-pod.yml kubectl apply -f postgres-service.yml kubectl apply -f worker-app-pod.yml kubectl apply -f result-app-pod.yml kubectl apply -f result-app-service.yml
App 테스트 하기
voting-app, result-app service 주소 확인
windows 에서 접속해 보기
docker desktop 을 설치해 사용하고 있다면 chrome 에서 http://192.168.49.2:30004, http://192.168.49.2:30005 를 접속해 바로 확인할 수 있다. docker desktop 이 설치가 되어 있지 않다면, wsl2 ubuntu 터미널에서 nginx 설치 (설치시 --with-stream 옵션 필요) 후 proxy 로 연결해 확인할 수 있다. 이때 nginx.conf 에 아래를 추가한다.
stream { upstream minikube-voting { server 192.168.49.2:30004; } server { listen 30004; proxy_pass minikube-voting; } upstream minikube-result { server 192.168.49.2:30005; } server { listen 30005; proxy_pass minikube-result; } } http { include mime.types; ... }
이제 windows chrome 브라우저에서 아래처럼 접속할 수 있다.
http://localhost:30004 --> http://192.168.49.2:30004
http://localhost:30005 --> http://192.168.49.2:30005
'kubernetes' 카테고리의 다른 글
Kubernetes Services (0) 2021.12.25 Kubernetes Deployment (0) 2021.12.20 Kubernetes ReplicaSet 생성, 확인, 수정, 삭제하기 (0) 2021.12.20 Kubernetes Pod 생성, 확인, 수정, 삭제하기 (0) 2021.12.11