Menu Close
4.5.4. PostgreSQL 데이터베이스 서비스에 Spring PetClinic 샘플 애플리케이션 연결
샘플 애플리케이션을 데이터베이스 서비스에 연결하려면 Service Binding Operator를 트리거하는 ServiceBinding
CR(사용자 정의 리소스)을 생성하여 바인딩 데이터를 애플리케이션에 예상해야 합니다.
프로세스
바인딩 데이터를 예상하는
ServiceBinding
CR을 생성합니다.$ oc apply -f - << EOD --- apiVersion: binding.operators.coreos.com/v1alpha1 kind: ServiceBinding metadata: name: spring-petclinic-rest namespace: my-postgresql spec: services: 1 - group: postgresql.dev4devs.com version: v1beta1 kind: Database 2 name: sampledatabase version: v1alpha1 application: 3 name: spring-petclinic-rest group: apps version: v1 resource: deployments EOD
바인딩 데이터를 샘플 애플리케이션으로 프로젝션할 수 있도록 출력에서
ServiceBinding
CR이 생성되었는지 확인합니다.출력 예
servicebinding.binding.operators.coreos.com/spring-petclinic-rest created
바인딩에 성공했는지 확인하려면 바인딩 리소스의 상태 조건을 확인합니다.
$ oc get servicebindings spring-petclinic-rest -n my-postgresql -o jsonpath-as-json='{.status.conditions}'
출력 예
[ [ { "lastTransitionTime": "2021-09-06T13:42:28Z", "message": "", "reason": "DataCollected", "status": "True", "type": "CollectionReady", }, { "lastTransitionTime": "2021-09-06T13:42:28Z", "message": "", "reason": "ApplicationUpdated", "status": "True", "type": "InjectionReady", }, { "lastTransitionTime": "2021-09-06T13:42:28Z", "message": "", "reason": "ApplicationsBound", "status": "True", "type": "Ready", }, ], ]
기본적으로 데이터베이스 서비스의 바인딩 데이터의 값은 샘플 애플리케이션을 실행하는 워크로드 컨테이너에 파일로 예상됩니다.
생성된 후에는 토폴로지로 이동하여 시각적 연결을 확인할 수 있습니다.
그림 4.1. Spring-petclinic-rest와 sampledatabase 연결
로컬 환경에서 샘플 애플리케이션에 액세스하도록 애플리케이션 포트에서 포트 전달을 설정합니다.
$ oc port-forward --address 0.0.0.0 svc/spring-petclinic-rest 9966:80 -n my-postgresql
http://localhost:9966/petclinic 액세스합니다.
이제 localhost:9966에서 Spring PetClinic 샘플 애플리케이션에 원격으로 액세스할 수 있습니다.
애플리케이션이 이제 데이터베이스 서비스에 연결되어 있는지 확인하려면 모든 애완동물 목록에 액세스합니다.
$ curl -X GET "http://localhost:9966/petclinic/api/pets" -H "accept: application/json"
출력 예
[{"id":1,"name":"Leo","birthDate":"2000/09/07","type":{"id":1,"name":"cat"}, "owner":{"id":1,"firstName":"George","lastName":"Franklin","address":"110...
이전 출력은 초기에 구성된 샘플 데이터를 표시하고 애플리케이션이 현재 데이터베이스 서비스에 연결되어 있는지 확인합니다.