This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.18.2.2. 2 단계: 서비스 사용
이제 서비스와 끝점이 정의되었으므로 적절한 컨테이너에서 환경 변수를 설정하여 서비스를 사용할 자격 증명에 대한 적절한 Pod 액세스 권한을 부여합니다.
kind: "DeploymentConfig" apiVersion: "v1" metadata: name: "my-app-deployment" spec: strategy: type: "Rolling" rollingParams: updatePeriodSeconds: 1 intervalSeconds: 1 timeoutSeconds: 120 replicas: 2 selector: name: "frontend" template: metadata: labels: name: "frontend" spec: containers: - name: "helloworld" image: "origin-ruby-sample" ports: - containerPort: 3306 protocol: "TCP" env: - name: "MYSQL_USER" value: "${MYSQL_USER}" - name: "MYSQL_PASSWORD" value: "${MYSQL_PASSWORD}" - name: "MYSQL_DATABASE" value: "${MYSQL_DATABASE}"
kind: "DeploymentConfig"
apiVersion: "v1"
metadata:
name: "my-app-deployment"
spec:
strategy:
type: "Rolling"
rollingParams:
updatePeriodSeconds: 1
intervalSeconds: 1
timeoutSeconds: 120
replicas: 2
selector:
name: "frontend"
template:
metadata:
labels:
name: "frontend"
spec:
containers:
-
name: "helloworld"
image: "origin-ruby-sample"
ports:
-
containerPort: 3306
protocol: "TCP"
env:
-
name: "MYSQL_USER"
value: "${MYSQL_USER}"
-
name: "MYSQL_PASSWORD"
value: "${MYSQL_PASSWORD}"
-
name: "MYSQL_DATABASE"
value: "${MYSQL_DATABASE}"
외부 데이터베이스 환경 변수
애플리케이션에서 외부 서비스를 사용하는 것은 내부 서비스를 사용하는 것과 유사합니다. 이전 단계에서 설명한 자격 증명을 사용하여 서비스에 대한 환경 변수 및 추가 환경 변수가 할당됩니다. 예를 들어 MySQL 컨테이너는 다음과 같은 환경 변수를 수신합니다.
-
EXTERNAL_MYSQL_SERVICE_SERVICE_HOST=<ip_address>
-
EXTERNAL_MYSQL_SERVICE_SERVICE_PORT=<port_number>
-
MYSQL_USERNAME=<mysql_username>
-
MYSQL_PASSWORD=<mysql_password>
-
MYSQL_DATABASE_NAME=<mysql_database>
애플리케이션은 환경에서 서비스에 대한 좌표와 자격 증명을 읽고 서비스를 통해 데이터베이스와의 연결을 설정합니다.