cej55 / carsharing

car-sharing msa
0 stars 2 forks source link

배포 #5

Open cej55 opened 3 years ago

cej55 commented 3 years ago

<<< 운영 >>> 1.리소스 만들기 : 리소스 그룹, AKS, ACR 생성 2.클러스터(VM) 클라우드에서 쿠버네티스 클라이언트 설치 및 Azure 클라우드와 연결 3.github 소스 다운로드 4.도커 이미지 생성 및 ACR 등록 도커이미지명 reservation : carsharing-reservation:v1 payment : carsharing-payment:v1 rental : carsharing-rental:v1 payment : carsharing-customer:v1 5.컨테이너 및 서비스 생성(배포하기: resevation 기준) 6.배포상태 보기: 배포된 객체 상태 보기 7.컨네이너 실행 노드 서버로 들어가기 8.배포 삭제

  1. payment, rental, customer 배포 및 확인

  2. gateway 배포 및 확인

  3. 전체 시나리오 확인

  4. 리소스 만들기 portal.azure.com 사이트 로그인 홈 이동은 상단'Microsoft Azure' 클릭 1.1 리스스 그룹 생성 상단 검색 창에 : 리소스 그룹 검색 리소스 그룹 만들기 리소스 그룹명 :user04-skcc-rsrcgrp 한국중부 하단 검토+만들기 하단 만들기 1.2 AKS 클러스터 생성 (AzureKubernetesService) 상단 검색창에 : kube 검색 Kubernetes 서비스 선택 왼쪽 + 추가 > + kuubernetes클러스터 추가 리소스 그룹 선택 클러스터이름 입력창에서 이름 입력: user04-skcc-aks 노드 크기 4로 수정 검토 + 만들기 만들기 상단 알람 클릭하면 진행상황 재확인 1.3 컨테이너 레지스터리 생성 상단 검색창에 : 컨테이너 검색 서비스 > 컨테이너 레지스트리 선택

    • 만들기 선택 리소스 그룹 선택 레지스트리 이름 : user04skccacr, 저장소 : .azurecr.io 검토 + 만들기 만들기 상단 알람 클릭하면 진행상황 재확인
  5. 클러스터(VM) 클라우드에서 접속 및 Azure 클라우드와 연결 .클러스터(VM) 클라우드 접속 .클러스터(VM) 클라우드에 쿠버네티스 설치(기 설치되어 있음) .쿠버네티스 클라이언트 와 리소스 연결(SSO) .쿠버네티스 클라이언트 AKS 와ACR 연결(마운트) 2.1 클라우드 쿠버테스트 클라이언트 접속 portal.azure.com 들어가서 상단 Cloud shell 버튼 클릭 2.2 쿠버네티스 클라이언트 클라우드와 리소스 연결 2.2.1 az login ==> 리소스와 클라이언트 연결 결과 하단 url 링크 클릭(Ctrl + url 선택 : 새로운 브라우저 팝업) 결과 하단 접속 코드 대문자 복사 링크 화면 접속 코드 입력화면에서 붙여넣기 계정 선택 : user22* 계정보호 건너띠기 ==> 클라우드 쿠버네티스 클라이언트와 리소스세션 연결됨(sso 맺어짐) Terminal 에서 연결 확인 리소스확인 종량제 == 2.2.3 AKS (Azure Kubernetes Service) 생성 => portal azure에서 생성했으므로 스킵 == az aks create --resource-group user04-skcc-rsrcgrp --name user04-skcc-aks --node-count 2 --enable-addons monitoring --generate-ssh-keys 2.2.4 쿠버네티스 클라이언트 환경과 azure 쿠버네티스 서비스와 연결 az aks get-credentials --resource-group user04-skcc-rsrcgrp --name user04-skcc-aks kubectl config current-context => 연결 aks 확인 2.2.5 azure 쿠버네티스 클러스터와 ACR 클라이언트 azure ACR 와 바인딩 === ACR (Azure Container Registry) 생성 => portal azure에서 생성했으므로 스킵 === az acr create --resource-group user22-rsrcgrp --name user22skccacr --sku Basic az aks update -n user04-skcc-aks -g user04-skcc-rsrcgrp --attach-acr user04skccacr == 2.2.6 Azure ACR Login 설정 == az acr login --name hanchyacr --expose-token

  6. github에서 소스 다운로드 3.1 github repository 폴더 생성 및 이동 mkdir git_repo cd git_repo 3.2 github 소스 내려받기
    git clone https://github.com/hanchy-git/carsharing.git => github에서 최초 소스 복제 git pull https://github.com/hanchy-git/carsharing.git => github에서 최신 소스 다운로드 최신 소스로 덥어쓰기 git fetch --all git reset --hard origin/main carsharing 폴더 이동 및 소스 확인

4.도커이미지 생성 및 acr에 등록(payment 먼저) 4.1 서비스 소스 폴더로 이동 git_repo/carsharing/payment 이동 4.2 소스 빌드 mvn package -Dmaven.test.skip=true ==> 사용안함 : azure bash shell에서 작동 안됨 4.3 docker로 이미지 빌드 및 acr 등록 4.3.1 이미지 빌드 이미지명 : carsharing-reservation docker build -t hanchyacr.azurecr.io/carsharing-payment:latest . 4.3.2 docker 이미지 생성 확인 docker image ls 4.3.3 docker 이미지 acr에 등록
az acr login --name user04skccacr docker push user22skccacr.azurecr.io/carsharing-payment:latest <=== 사용안함 : azure bash shell에서 작동 안됨
4.4 acr로이미지 빌드 및 acr 등록 az acr login --name user04skccacr az acr build --registry user04skccacr --image user04skccacr.azurecr.io/carsharing-reservation:latest --file Dockerfile . az acr build --registry user04skccacr --image user04skccacr.azurecr.io/carsharing-payment:latest --file Dockerfile . az acr build --registry user04skccacr --image user04skccacr.azurecr.io/carsharing-rental:latest --file Dockerfile . az acr build --registry user04skccacr --image user04skccacr.azurecr.io/carsharing-customer:latest --file Dockerfile . 빌드 오류시 다시 시도 Head https://registry-1.docker.io/v2/library/openjdk/manifests/8u212-jdk-alpine: Get https://auth.docker.io/token?scope=repository%3Alibrary%2Fopenjdk%3Apull&service=registry.docker.io: net/http: request canceled (Client.Timeout exceeded while awaiting headers) 2021/06/13 16:17:28 Container failed during run: build. No retries remaining. failed to run step ID: build: exit status 1

Run ID: de7 failed after 24s. Error: failed during run, err: exit status 1 Run failed

4.5 acr 등록 확인 portal.azure.com 에서 커테이너 레지트리 > 리포지터리 에서 확인
5.컨테이너 및 서비스 생성(배포)(payment 기준) ==> 한번만 === 5.1 kubectl config current-context 5.2 kubectl get all 5.3 namespace 생성 => 이거는 한번만 kubectl create namespace ns-carsharing kubectl get ns 5.4 configMap 생성 kubectl create configmap cm-carsharing --namespace="ns-carsharing" --from-literal=DB_IP=10.20.30.1 --from-literal=DB_SERVICE_NAME=CARS kubectl get cm -n ns-carsharing === 한번만 <== 5.5 yaml 로 컨테이너 생성(배포) 5.5.1 reservation/kubernetes 폴더 이동 5.5.2 Deployment 배포 deployment.yml 파일에서 도커이미지 저장소로 수정 image: user04skccacr.azurecr.io/carsharing-payment:latest

readinessProbe:

httpGet:

path: '/actuator/health'

port: 8080

initialDelaySeconds: 10

timeoutSeconds: 2

periodSeconds: 5

failureThreshold: 10

livenessProbe:

httpGet:

path: '/actuator/health'

port: 8080

initialDelaySeconds: 120

timeoutSeconds: 2

periodSeconds: 5

failureThreshold: 5

     kubectl apply -f deployment.yml -n ns-carsharing
     kubectl get deploy reservation -o yaml -n ns-carsharing
     kubectl get pod -n ns-carsharing
     kubectl get pod -w -n ns-carsharing => 배포 확인
        READY : 1/1 
        STATUS : Running

     kubectl describe pod/reservation-85f78dbc4-m2zzc -n ns-carsharing 
     kubectl logs pod/reservation-85f78dbc4-m2zzc -n ns-carsharing
     kubectl logs -f pod/reservation-85f78dbc4-m2zzc -n ns-carsharing 

     watch -n 1 kubectl get pod -n ns-carsharing => pod 모니터링, 새로운 터미널에서
     kubectl get pod -o wide -n ns-carsharing => 배포 확인
     kubectl exec -it pod/객체이름 -n ns-carsharing -- /bin/bash  => 컨테이너 노드로 들어감
       env
         DB_IP, DB_SERVICE  확인 => configMap 환경변수 설정 확인
       exit
 5.5.3. 서비스 생성(배포) 
   kubectl apply -f service.yaml -n ns-carsharing
   kubectl get svc -n ns-carsharing
     external ip, port 확인      
 5.5.4 크롬 브라우저에 ip 입력하여 결과확인
    http://20.194.61.93/payments
    http://20.194.61.93/reservations
    http://20.194.61.93/rentals
    http://20.194.61.93/customers
 5.5.5 크롬 브라우저에 configMap 확인   ==> reservation 배포 후 확인
    http://ip:포트/env 

6.배포 상태 보기 강의 > Kubernetes 최소 배포단위 Pod 입장 6.1 Labs > 새 터미널 클릭 6.2 pod, delpoly, service 상태 확인 kubectl get all 모든 type kubectl get pod pod type 만 kubectl get pod/nginx-6799fc88d8-w475t kubectl get deploy deploy type만 kubectl get deploy -o wide deploy type만 추가 정보 kubectl get pod -o wide pod 추가 정보, 클러스터 ip, node 정보확인 kubectl get node 노드 개수 확인 6.3 pod 상태 kubectl get pod -w
Status ImagePullBackOff/ ErrImagePull 일때=> 도커이미지가 존재하지 않을 경우 발생 kubectl describe [pod/객체 이름] Status Running CrashLoopBackOff/Error 일때 => 컨테이너가 실행시 오류가발생 kubectl logs [pod/객체 이름] => 81페이지 kubectl logs pods -n ns-carsharing => 마지막 로그 확인 kubectl describe pods -n ns-carsharing kubectl logs -f reservation-85f78dbc4-m2zzc -n ns-carsharing => 실시간 로그 모니터링

 Status가 Running이지만 서비스가 정상적이지 않을때  => 컨테이너 실행 서버로 들어가서(터미널) 확인 방법
   kubectl exec -it [pod/객체 이름] -n ns-carsharing /bin/bash => 81페이지
    ls
    df -k
    curl localhost:80
    exit
  1. 컨네이너 실행 노드 서버로 들어가기 kubectl get pod -o wide pod 추가 정보, 클러스터 ip, node 정보확인 kubectl exec -it [pod/객체 이름] -- /bin/bash => 81페이지 ls df -k curl localhost:8081/reservations exit

  2. 배포 삭제 kubectl delete deploy/reservation -n ns-carsharing kubectl delete pod/reservation-676c9c5574-285x8 -n ns-carsharing kubectl delete service/reservation -n ns-carsharing kubectl delete cm/cm-carsharing -n ns-carsharing kubectl delete deploy, svc --all -n ns-carsharing kubectl delete ns ns-carsharing

    kubectl delete pod 객체이름 79 페이지 kubectl delete deploy,service --all

  3. reservation, rental, customer 배포 및 확인 위 4 ~ 5번으로 배포 도커이미지명 reservation : carsharing-reservation:latest rental : carsharing-rental:latest customer : carsharing-customer:latest

  4. gateway 배포 및 확인 mvn package -Dmaven.test.skip=true az acr build --registry user04skccacr --image user04skccacr.azurecr.io/carsharing-gateway:latest --file Dockerfile . kubectl create deploy gateway --image=user04skccacr.azurecr.io/carsharing-gateway:latest -n ns-carsharing kubectl expose deploy gateway --type="LoadBalancer" --port=8080 -n ns-carsharing kubectl get svc -n ns-carsharing gateway EXTERNAL-IP, 포트 확인

    kubectl get pod -n ns-carsharing

    curl http://20.84.24.69:8080/reservations

    kubectl delete deploy/gateway -n ns-carsharing kubectl delete service/gateway -n ns-carsharing

    kubectl exec -it pod/gateway-7b785bcbc7-t6w42 -n ns-carsharing /bin/sh kubectl get deploy/gateway -o yaml -n ns-carsharing

    kubectl logs pod/gateway-7b785bcbc7-t6w42 -n ns-carsharing

  5. 전체 시나리오 확인(게이트웨이 IP 및 포트로 사용) 소스구현 8번 참조하여 실행 http://20.194.61.93/reseve_action.html http://20.194.61.93/return_action.html http://20.194.61.93/cancel_action.html http://20.194.61.93/rental-action.html http://20.194.61.93/retrive-action.html

http://20.194.61.93/reservations http://20.194.61.93/payments http://20.194.61.93/rentals http://20.194.61.93/customers

cej55 commented 3 years ago

github에서 소스 다운로드 3.1 github repository 폴더 생성 및 이동 cd clouddrive mkdir git_repo cd git_repo 3.2 github 소스 내려받기 git clone https://github.com/hanchy-git/carsharing.git => github에서 최초 소스 복제 git pull https://github.com/hanchy-git/carsharing.git => github에서 최신 소스 다운로드 ==> 안됨 carsharing 폴더 이동 및 소스 확인 4.도커이미지 생성 및 acr에 등록(reservation 기준) 4.1 Docker 이미지 생성 및 acr에 등록 4.1.1 서비스 소스 폴더로 이동 git_repo/carsharing/reservation 이동 4.2.2 소스 빌드 mvn package 4.2.3 docker 이미지 빌드 az acr login --name jychung88acr 이미지명 : carsharing-reservation docker build -t jychung88acr.azurecr.io/carsharing-reservation:v1 . => 안됨 docker build -t turkyman/carsharing-reservation:v1 . => 못함 4.2.4 docker 이미지 생성 확인 docker image ls ==> 안됨 4.2.5 docker 이미지 acr에 등록 docker push user22skccacr.azurecr.io/carsharing-reservation:v1 => user22skccacr.azurecr.io : acr 레파지터리로 수정 ==> 못함

아래 명령어로 만듬 az acr build --registry jychung88acr --image jychung88acr.azurecr.io/carsharing-reservation:v1 . 결과는 생성됨 image

http://www.yamllint.com/

cej55 commented 3 years ago

5.컨테이너 및 서비스 생성(배포)(reservation 기준) 5.1 kubectl config current-context 5.2 kubectl get all 5.3 배포(API 방식) 5.3.1 Deployment 배포 kubectl create deployment carsharing-reservation --image=jychung88acr.azurecr.io/carsharing-reservation:v1 => ok kubectl get all pod, deployment, replicaset image

5.3.2 service 배포 kubectl expose deploy carsharing-reservation --type=LoadBalancer --port=80 kubectl get svc external ip, port 확인 5.3.3 크롬 브라우저에 ip 입력하여 결과확인 image http://ip:포트/reserve_action.html

5.4 yaml 로 컨테이너 생성(배포) 5.4.1 reservation/kubernetes 폴더 이동 5.4.2 Deployment 배포 deployment.yml 파일에서 도커이미지 저장소로 수정 image: jychung88acr.azurecr.io/carsharing-reservation:v1 yml파일 수정함 2칸씩 뒤로... image

kubectl apply -f deployment.yml kubectl get pod => 배포 확인 image

5.4.3. 서비스 생성(배포) kubectl apply -f service.yaml kubectl get svc external ip, port 확인 5.4.4 크롬 브라우저에 ip 입력하여 결과확인 http://ip:포트/reserve_action.html 몬가 잘못한듯 image

6.배포 상태 보기 강의 > Kubernetes 최소 배포단위 Pod 입장 6.1 Labs > 새 터미널 클릭 6.2 pod, delpoly, service 상태 확인 kubectl get all 모든 type kubectl get pod pod type 만 kubectl get pod/nginx-6799fc88d8-w475t kubectl get deploy deploy type만 kubectl get deploy -o wide deploy type만 추가 정보 kubectl get pod -o wide pod 추가 정보, 클러스터 ip, node 정보확인 kubectl get node 노드 개수 확인 6.3 pod 상태 kubectl get pod -w Status ImagePullBackOff/ ErrImagePull 일때=> 도커이미지가 존재하지 않을 경우 발생 kubectl describe [pod/객체 이름] Status Running CrashLoopBackOff/Error 일때 => 컨테이너가 실행시 오류가발생 kubectl logs [pod/객체 이름] => 81페이지 Status가 Running이지만 서비스가 정상적이지 않을때 => 컨테이너 실행 서버로 들어가서(터미널) 확인 방법 kubectl exec -it [pod/객체 이름] -- /bin/bash => 81페이지 ls df -k curl localhost:80 exit

컨네이너 실행 노드 서버로 들어가기 kubectl get pod -o wide pod 추가 정보, 클러스터 ip, node 정보확인 kubectl exec -it [pod/객체 이름] -- /bin/bash => 81페이지 ls df -k curl localhost:8081/reservations exit

배포 삭제 kubectl delete pod 객체이름 79 페이지 kubectl delete deploy,service --all

payment, rental, customer 배포 및 확인 위 4 ~ 5번으로 배포 도커이미지명 payment : carsharing-payment:v1 rental : carsharing-rental:v1 payment : carsharing-customer:v1

gateway 배포 및 확인

전체 시나리오 확인 소스구현 8번 참조하여 실행

yml파일 검증기 http://www.yamllint.com/

cej55 commented 3 years ago

payment

git_repo/carsharing/payment 이동 mvn package

az acr build --registry jychung88acr --image jychung88acr.azurecr.io/carsharing-payment:v1 . kubectl create deployment carsharing-payment --image=jychung88acr.azurecr.io/carsharing-payment:v1 kubectl expose deploy carsharing-payment --type=LoadBalancer --port=80 kubectl get all image image

cej55 commented 3 years ago

rental

git_repo/carsharing/rental 이동 mvn package

az acr build --registry jychung88acr --image jychung88acr.azurecr.io/carsharing-rental:v1 . git_repo/carsharing/rental/kubernetes 이동 kubectl create -f deployment.yml kubectl get deploy 수정 image

kubectl create -f service.yaml kubectl get all

아래 문제 발생 image