728x90

목차

     

    준비 자료

    아래 깃허브의 올린 자료를 clone 받아서 따라 하면 이해하는 데 많은 도움이 될 것이다.

    https://github.com/Parkjinman/spring-cloud-msa

     

    GitHub - Parkjinman/spring-cloud-msa: spring-cloud 라이브러리를 활용해서 만든 msa framework

    spring-cloud 라이브러리를 활용해서 만든 msa framework. Contribute to Parkjinman/spring-cloud-msa development by creating an account on GitHub.

    github.com

     

    msa 프레임워크 이미지 생성

     

    생성한 이미지 docker registry에 push 

    $ docker login
    Log in with your Docker ID or email address to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com/ to create one.
    You can log in with your password or a Personal Access Token (PAT). Using a limited-scope PAT grants better security and is required for organizations using SSO. Learn more at https://docs.docker.com/go/access-tokens/
    
    Username: 
    Password:
    Login Succeeded
    docker tag 880bb13d1f56 ${your-account}/spring-cloud-msa-business-service:v20240405
    docker push ${your-account}/spring-cloud-msa-business-service:v20240405
    
    docker tag 67d5c6ae5bc2 ${your-account}/spring-cloud-msa-batch-service:v20240405
    docker push ${your-account}/spring-cloud-msa-batch-service:v20240405
    
    docker tag ccf2b0ace4e4 ${your-account}/spring-cloud-msa-user-service:v20240405
    docker push ${your-account}/spring-cloud-msa-user-service:v20240405
    
    docker tag 248946dc9fbd ${your-account}/spring-cloud-msa-gateway-service:v20240405
    docker push ${your-account}/spring-cloud-msa-gateway-service:v20240405
    
    docker tag ab63301eea96 ${your-account}/spring-cloud-msa-discovery-service:v20240405
    docker push ${your-account}/spring-cloud-msa-discovery-service:v20240405
    
    docker tag 918889c458dd ${your-account}/spring-cloud-msa-postgres:v20240405
    docker push ${your-account}/spring-cloud-msa-postgres:v20240405

     

    저장된 docker hub의 이미지를 기준으로 deployment.yaml, service.yaml 작성

    필자는 미리 작성해 뒀다. 이것의 이미지 경로만 수정하여 사용하면 된다.

     

    작성한 deployment.yaml, service.yaml로 helm chart 자동 변환

    helmify - deployment.yaml, service.yaml을 helm으로 자동으로 변환시켜 주는 도구이다.

    helmify 설치

    wget https://github.com/arttor/helmify/releases/download/v0.3.8/helmify_0.3.8_Linux_64-bit.tar.gz
    
    tar xvfz helmify_0.3.8_Linux_64-bit.tar.gz
    
    sudo mv helmify /usr/local/bin/.

     

    helmify 사용하기

    user@datapecker3:~/workspace/spring-cloud-app$ tree
    .
    ├── batch-deployment.yaml
    ├── batch-service.yaml
    ├── business-deployment.yaml
    ├── business-service.yaml
    ├── discovery-deployment.yaml
    ├── discovery-service.yaml
    ├── gateway-deployment.yaml
    ├── gateway-service.yaml
    ├── postgres-deployment.yaml
    ├── postgres-service.yaml
    ├── user-deployment.yaml
    └── user-service.yaml
    user@datapecker3:~/workspace/spring-cloud-app$ awk 'FNR==1 && NR!=1  {print "---"}{print}' *.yaml | helmify msa-helm

    msa-helm 파일이 생성된다.

    user@datapecker3:~/workspace/spring-cloud-app$ tree
    .
    ├── batch-deployment.yaml
    ├── batch-service.yaml
    ├── business-deployment.yaml
    ├── business-service.yaml
    ├── discovery-deployment.yaml
    ├── discovery-service.yaml
    ├── gateway-deployment.yaml
    ├── gateway-service.yaml
    ├── msa-helm
    │   ├── Chart.yaml
    │   ├── templates
    │   │   ├── batch-service.yaml
    │   │   ├── deployment.yaml
    │   │   ├── discovery-service.yaml
    │   │   ├── gateway-service.yaml
    │   │   ├── _helpers.tpl
    │   │   ├── kubernetes-service.yaml
    │   │   ├── postgres.yaml
    │   │   └── user-service.yaml
    │   └── values.yaml
    ├── postgres-deployment.yaml
    ├── postgres-service.yaml
    ├── user-deployment.yaml
    └── user-service.yaml

    templates 폴더에 들어가서 모든 service.yaml의 metadata.name: 에서 {{ include "msa-helm.fullname" . }}- 꼭 이걸 지워야 한다.

     

    helm 설치 테스트

    user@datapecker3:~/workspace/spring-cloud-app$ cd msa-helm
    user@datapecker3:~/workspace/spring-cloud-app/msa-helm$ helm install spring-cloud-msa-app . --namespace msa-ns
    WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /etc/kubernetes/admin.conf
    WARNING: Kubernetes configuration file is world-readable. This is insecure. Location: /etc/kubernetes/admin.conf
    NAME: spring-cloud-msa-app
    LAST DEPLOYED: Fri Apr  5 08:43:09 2024
    NAMESPACE: msa-ns
    STATUS: deployed
    REVISION: 1
    TEST SUITE: None

     

    성공 화면

     

    포트포워딩으로 외부접속

    nohup kubectl port-forward --address=0.0.0.0 -n msa-ns service/discovery-service 8761:8761>> /opt/apps/kubernetes/logs/discovery.out 2>&1 &
    nohup kubectl port-forward --address=0.0.0.0 -n msa-ns service/gateway-service 9000:9000>> /opt/apps/kubernetes/logs/gateway.out 2>&1 &
    nohup kubectl port-forward --address=0.0.0.0 -n msa-ns service/postgres  5432:5432>> /opt/apps/kubernetes/logs/postgres.out 2>&1 &
    Talend API Tester

    API Gateway를 통해 user-service에 라우팅 되어 회원가입이 정상 실행되는 것을 확인할 수 있다.

     

    helm chart github에 push

    msa-helm 파일 내용을 자신의 github에 commit & push를 한다.

    https://github.com/Parkjinman/spring-cloud-helm

     

    GitHub - Parkjinman/spring-cloud-helm: spring cloud helm chart

    spring cloud helm chart. Contribute to Parkjinman/spring-cloud-helm development by creating an account on GitHub.

    github.com

     

    helm uninstall로 실행한 app 제거

    마무리로 CI & CD를 구축하면 argocd로 배포를 해야 하기 때문에 기존에 테스트로 실행한 helm은 삭제한다.

    helm uninstall spring-cloud-msa-app -n msa-ns
    728x90
    TOP