11.2. ConfigMap 속성 소스에 대한 튜토리얼 실행


다음 튜토리얼에서는 Kubernetes Secrets 및 ConfigMap 설정을 실험할 수 있습니다. Kubernetes 통합 활성화에 설명된 대로 Spring Cloud Kubernetes 플러그인을 활성화하여 Kubernetes 구성 오브젝트를 Spring Boot Externalized Configuration과 통합합니다.

11.2.1. Spring Boot Camel Config 빠른 시작 실행

다음 튜토리얼에서는 Kubernetes Secrets 및 ConfigMaps를 설정할 수 있는 spring-boot-camel-config-archetype Maven archetype을 기반으로 합니다.

절차

  1. 새 쉘 프롬프트를 열고 다음 Maven 명령을 입력하여 간단한 Camel Spring Boot 프로젝트를 생성합니다.

    mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate \
      -DarchetypeCatalog=https://maven.repository.redhat.com/ga/io/fabric8/archetypes/archetypes-catalog/2.2.0.fuse-sb2-7_11_1-00018-redhat-00002/archetypes-catalog-2.2.0.fuse-sb2-7_11_1-00018-redhat-00002-archetype-catalog.xml \
      -DarchetypeGroupId=org.jboss.fuse.fis.archetypes \
      -DarchetypeArtifactId=spring-boot-camel-config-archetype \
      -DarchetypeVersion=2.2.0.fuse-sb2-7_11_1-00018-redhat-00002
    Copy to Clipboard Toggle word wrap

    archetype 플러그인이 대화형 모드로 전환하여 나머지 필드를 입력하라는 메시지를 표시합니다.

    Define value for property 'groupId': : org.example.fis
    Define value for property 'artifactId': : fuse711-configmap
    Define value for property 'version':  1.0-SNAPSHOT: :
    Define value for property 'package':  org.example.fis: :
    Confirm properties configuration:
    groupId: org.example.fis
    artifactId: fuse711-configmap
    version: 1.0-SNAPSHOT
    package: org.example.fis
    Y: : Y
    Copy to Clipboard Toggle word wrap

    메시지가 표시되면 groupId 값으로 org.example.fis 를 입력하고 artifactId 값에 fuse711-configmap 을 입력합니다. 나머지 필드에는 기본값을 수락합니다.

  2. OpenShift에 로그인하고 애플리케이션을 배포할 OpenShift 프로젝트로 전환합니다. 예를 들어 developer 사용자로 로그인하여 openshift 프로젝트에 배포하려면 다음 명령을 입력합니다.

    oc login -u developer -p developer
    oc project openshift
    Copy to Clipboard Toggle word wrap
  3. 명령줄에서 새 fuse711-configmap 프로젝트의 디렉터리로 변경하고 이 애플리케이션의 Secret 오브젝트를 생성합니다.

    cd fuse711-configmap
    oc create -f sample-secret.yml
    Copy to Clipboard Toggle word wrap
    참고

    애플리케이션을 배포하기 전에 Secret 오브젝트를 생성해야 합니다. 그러지 않으면 배포된 컨테이너가 시크릿을 사용할 수 있을 때까지 대기 상태가 됩니다. 이후에 시크릿을 생성하면 컨테이너가 대기 상태가 해제됩니다. Secret Object 설정 방법에 대한 자세한 내용은 시크릿 설정을 참조하십시오.

  4. 빠른 시작 애플리케이션을 빌드하고 배포합니다. fuse711-configmap 프로젝트의 최상위 수준에서 다음을 입력합니다.

    mvn oc:deploy -Popenshift
    Copy to Clipboard Toggle word wrap
  5. 다음과 같이 애플리케이션 로그를 확인합니다.

    1. 브라우저의 OpenShift 웹 콘솔로 이동합니다(https://OPENSHIFT_IP_ADDR, OPENSHIFT_IP_ADDR 을 클러스터의 IP 주소로 교체) 자격 증명으로 로그인합니다(예: 사용자 이름 개발자 및 암호, developer).
    2. 왼쪽 패널에서 을 확장합니다. 상태를 클릭하여 프로젝트 상태 페이지를 확인합니다. 선택한 네임스페이스(예: openshift)의 기존 애플리케이션이 모두 표시됩니다.
    3. fuse711-configmap 을 클릭하여 빠른 시작에 대한 개요 정보 페이지를 확인합니다.
    4. 왼쪽 패널에서 워크로드 를 확장합니다.
    5. Pod 를 클릭한 다음 fuse711-configmap-xxxx 를 클릭합니다. 애플리케이션의 Pod 세부 정보가 표시됩니다.
    6. 로그 탭을 클릭하여 애플리케이션 로그를 확인합니다.
  6. CloudEvent/ main/resources/application.properties 에 구성된 기본 수신자 목록은 생성된 메시지를 두 개의 더미 엔드포인트인 direct:async-queuedirect:file 로 보냅니다. 이렇게 하면 다음과 같은 메시지가 애플리케이션 로그에 기록됩니다.

    5:44:57.377 [Camel (camel) thread #0 - timer://order] INFO  generate-order-route - Generating message message-44, sending to the recipient list
    15:44:57.378 [Camel (camel) thread #0 - timer://order] INFO  target-route-queue - ----> message-44 pushed to an async queue (simulation)
    15:44:57.379 [Camel (camel) thread #0 - timer://order] INFO  target-route-queue - ----> Using username 'myuser' for the async queue
    15:44:57.380 [Camel (camel) thread #0 - timer://order] INFO  target-route--file - ----> message-44 written to a file
    Copy to Clipboard Toggle word wrap
  7. ConfigMap 오브젝트를 사용하여 fuse711-configmap 애플리케이션의 구성을 업데이트하려면 먼저 OpenShift ApiServer에서 데이터를 볼 수 있는 fuse711-configmap 애플리케이션 권한을 부여해야 합니다. 다음 명령을 입력하여 fuse711-configmap 애플리케이션의 서비스 계정에 보기 권한을 부여합니다.

    oc policy add-role-to-user view system:serviceaccount:openshift:qs-camel-config
    Copy to Clipboard Toggle word wrap
    참고

    서비스 계정은 system:serviceaccount:PROJECT_NAME:SERVICE_ACCOUNT_NAME 구문을 사용하여 지정됩니다. fis-config 배포 설명자는 SERVICE_ACCOUNT_NAMEqs-camel-config 로 정의합니다.

  8. 실행 중인 실시간 다시 로드 기능을 보려면 다음과 같이 ConfigMap 오브젝트를 생성합니다.

    oc create -f sample-configmap.yml
    Copy to Clipboard Toggle word wrap

    새 ConfigMap은 실행 중인 애플리케이션에서 Camel 경로의 수신자 목록을 재정의하고, 생성된 메시지를 세 개의 더미 엔드포인트로 전송하도록 구성합니다. direct:async-queue,direct:file, direct:mail.mail . ConfigMap 오브젝트에 대한 자세한 내용은 ConfigMap 설정을 참조하십시오. 이렇게 하면 다음과 같은 메시지가 애플리케이션 로그에 기록됩니다.

    16:25:24.121 [Camel (camel) thread #0 - timer://order] INFO  generate-order-route - Generating message message-9, sending to the recipient list
    16:25:24.124 [Camel (camel) thread #0 - timer://order] INFO  target-route-queue - ----> message-9 pushed to an async queue (simulation)
    16:25:24.125 [Camel (camel) thread #0 - timer://order] INFO  target-route-queue - ----> Using username 'myuser' for the async queue
    16:25:24.125 [Camel (camel) thread #0 - timer://order] INFO  target-route--file - ----> message-9 written to a file (simulation)
    16:25:24.126 [Camel (camel) thread #0 - timer://order] INFO  target-route--mail - ----> message-9 sent via mail
    Copy to Clipboard Toggle word wrap

11.2.2. 구성 속성 console

구성 속성 빈은 삽입을 통해 구성 설정을 수신할 수 있는 일반 Java 빈입니다. Java 코드와 외부 구성 메커니즘 간의 기본 인터페이스를 제공합니다.

외부화된 구성 및 iPXE 레지스트리

다음 이미지에서는 Spring Boot 외부화된 구성이 spring-boot-camel-config 빠른 시작에서 작동하는 방법을 보여줍니다.

kube spring boot 01

구성 메커니즘에는 다음과 같은 주요 부분이 있습니다.

속성 소스
구성에 삽입하기 위한 속성 설정을 제공합니다. 기본 속성 소스는 애플리케이션의 application.properties 파일이며, ConfigMap 오브젝트 또는 Secret 오브젝트로 재정의할 수도 있습니다.
구성 속성 빈
속성 소스에서 configuraton 업데이트를 수신합니다. 구성 속성 빈은 @Configuration@ConfigurationProperties 주석으로 장식된 Java 빈입니다.
Spring opening 레지스트리
필수 주석을 사용하면 구성 속성 빈이 Spring console 레지스트리에 등록됩니다.
Camel console 레지스트리와 통합
Camel 빈 레지스트리는 Camel 경로에서 등록된 Spring 빈을 참조할 수 있도록 Spring console 레지스트리와 자동으로 통합됩니다.

QuickstartConfiguration 클래스

fuse711-configmap 프로젝트의 구성 속성ball은 다음과 같이 빠른 시작 구성 Java 클래스(이중요 /main/java/org/example/fis/ 디렉터리 아래)로 정의됩니다.

package org.example.fis;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

@Configuration  
1

@ConfigurationProperties(prefix = "quickstart")  
2

public class QuickstartConfiguration {

    /**
     * A comma-separated list of routes to use as recipients for messages.
     */
    private String recipients;  
3


    /**
     * The username to use when connecting to the async queue (simulation)
     */
    private String queueUsername;  
4


    /**
     * The password to use when connecting to the async queue (simulation)
     */
    private String queuePassword;  
5


    // Setters and Getters for Bean properties
    // NOT SHOWN
    ...
}
Copy to Clipboard Toggle word wrap
1
@Configuration 주석을 사용하면 빠른 시작Configuration 클래스가 ID인 QuickstartConfiguration.com으로 Spring에서 인스턴스화 및 등록됩니다. 이렇게 하면 Camel에서 빈에 자동으로 액세스할 수 있습니다. 예를 들어 target-route-queue 경로는 Camel 구문 ${ovn:quickstartConfiguration?method=getQueueUsername} 을 사용하여 queueUserName 속성에 액세스할 수 있습니다.
2
@ConfigurationProperties 주석은 속성 소스에서 속성 값을 정의할 때 사용해야 하는 접두사인 빠른 시작을 정의합니다. 예를 들어 속성 파일은 recipient 속성을 quickstart.recipients 로 참조합니다.
3
받는 사람 속성은 속성 소스에서 삽입할 수 있습니다.
4
queueUsername 속성은 속성 소스에서 삽입할 수 있습니다.
5
queuePassword 속성은 속성 소스에서 삽입할 수 있습니다.

11.2.3. 시크릿 설정

이 빠른 시작의 Kubernetes 보안은 추가 필수 단계를 제외하고 표준 방식으로 설정됩니다. Spring Cloud Kubernetes 플러그인은 시크릿의 마운트 경로로 구성되어야 런타임 시 시크릿을 읽을 수 있습니다. 보안을 설정하려면 다음을 수행합니다.

  1. 샘플 보안 오브젝트 생성
  2. 시크릿의 볼륨 마운트 구성
  3. Secret 속성을 읽도록 spring-cloud-kubernetes 구성

샘플 Secret 오브젝트

빠른 시작 프로젝트는 다음과 같이 샘플 Secret, sample-secret.yml 을 제공합니다. Secret 오브젝트의 속성 값은 항상 base64로 인코딩됩니다( base64 명령줄 유틸리티 사용). Pod의 파일 시스템에 시크릿이 마운트되면 값이 다시 일반 텍스트로 다시 디코딩됩니다.

sample-secret.yml 파일

apiVersion: v1
kind: Secret
metadata: 
1

  name: camel-config
type: Opaque
data:
  # The username is 'myuser'
  quickstart.queue-username: bXl1c2VyCg== 
2

  quickstart.queue-password: MWYyZDFlMmU2N2Rm 
3
Copy to Clipboard Toggle word wrap

1
metadata.name: 시크릿을 식별합니다. OpenShift 시스템의 다른 부분에서는 이 ID를 사용하여 보안을 참조합니다.
2
빠른 시작.queue-username: 빠른 시작Configuration 빈의 queueUsername 속성에 삽입해야 합니다. 값은 base64로 인코딩 되어야 합니다.
3
Quickstart.queue-password: 빠른 시작Configuration 빈의 queuePassword 속성에 삽입해야 합니다. 값은 base64로 인코딩 되어야 합니다.
참고

Kubernetes에서는 CamelCase에서 속성 이름을 정의할 수 없습니다(속성 이름이 모두 소문자여야 함). 이 제한을 해결하려면 Spring Boot가 queueUsername 과 일치하는 하이픈 양식 queue-username 을 사용합니다. 이를 통해 Spring Boot의 외부화된 구성에 대한 완화된 바인딩 규칙을 활용합니다.

시크릿의 볼륨 마운트 구성

보안을 볼륨 마운트로 구성하여 런타임에 보안을 로드하도록 애플리케이션을 구성해야 합니다. 애플리케이션이 시작되면 Secret 속성을 파일 시스템의 지정된 위치에서 사용할 수 있게 됩니다. 애플리케이션의 deployment.yml 파일은 Secret의 볼륨 마운트를 정의하는 CloudEvent /main/jkube/ 디렉터리에 있습니다.

deployment.yml 파일

spec:
  template:
    spec:
      serviceAccountName: "qs-camel-config"
      volumes: 
1

        - name: "camel-config"
          secret:
            # The secret must be created before deploying this application
            secretName: "camel-config"
      containers:
        -
          volumeMounts: 
2

            - name: "camel-config"
              readOnly: true
              # Mount the secret where spring-cloud-kubernetes is configured to read it
              # see src/main/resources/bootstrap.yml
              mountPath: "/etc/secrets/camel-config"
          resources:
#            requests:
#              cpu: "0.2"
#              memory: 256Mi
#            limits:
#              cpu: "1.0"
#              memory: 256Mi
             env:
              - name: SPRING_APPLICATION_JSON
               value: '{"server":{"undertow":{"io-threads":1, "worker-threads":2 }}}'
Copy to Clipboard Toggle word wrap

1
volumes 섹션에서 배포는 camel-config 라는 새 볼륨을 선언하고, camel-config 라는 Secret을 참조합니다.
2
volumeMounts 섹션에서 배포는 camel-config 볼륨을 참조하는 새 볼륨 마운트를 선언하고 Pod 파일 시스템의 /etc/secrets/camel-config 경로에 Secret 볼륨을 마운트해야 함을 지정합니다.

보안 속성을 읽도록 spring-cloud-kubernetes 구성

Spring Boot 외부 구성과 시크릿을 통합하려면 Spring Cloud Kubernetes 플러그인을 시크릿 마운트 경로로 구성해야 합니다. Spring Cloud Kubernetes는 지정된 위치에서 시크릿을 읽고 속성 소스로 Spring Boot에서 사용할 수 있도록 합니다. Spring Cloud Kubernetes 플러그인은 빠른 시작 프로젝트의 CloudEvent /main/resources 에 있는 bootstrap.yml 파일의 설정으로 구성됩니다.

bootstrap.yml file

# Startup configuration of Spring-cloud-kubernetes
spring:
  application:
    name: camel-config
  cloud:
    kubernetes:
      reload:
        # Enable live reload on ConfigMap change (disabled for Secrets by default)
        enabled: true
      secrets:
        paths: /etc/secrets/camel-config
Copy to Clipboard Toggle word wrap

spring.cloud.kubernetes.secrets.paths 속성은 Pod에 보안 볼륨 마운트 경로 목록을 지정합니다.

참고

bootstrap.properties 파일(또는 bootstrap.yml 파일)은 application.properties 파일과 유사하게 작동하지만 애플리케이션 시작 초기 단계에서 로드됩니다. bootstrap.properties 파일에서 Spring Cloud Kubernetes 플러그인과 관련된 속성을 설정하는 것이 더 안정적입니다.

11.2.4. ConfigMap 설정

ConfigMap 오브젝트를 생성하고 보기 권한을 적절하게 설정하는 것 외에도 Spring Cloud Kubernetes와의 통합에서는 프로젝트의 bootstrap.yml 파일에 구성된 Spring .application.name 속성 값과 ConfigMap의 metadata.name 을 일치시켜야 합니다. ConfigMap을 설정하려면 다음을 수행합니다.

  • 샘플 ConfigMap 오브젝트 생성
  • 보기 권한 설정
  • Spring Cloud Kubernetes 플러그인 구성

샘플 ConfigMap 오브젝트

빠른 시작 프로젝트는 샘플 ConfigMap, sample-configmap.yml 을 제공합니다.

kind: ConfigMap
apiVersion: v1
metadata: 
1

  # Must match the 'spring.application.name' property of the application
  name: camel-config
data:
  application.properties: | 
2

    # Override the configuration properties here
    quickstart.recipients=direct:async-queue,direct:file,direct:mail 
3
Copy to Clipboard Toggle word wrap
1
metadata.name: ConfigMap을 식별합니다. OpenShift 시스템의 다른 부분에서는 이 식별자를 사용하여 ConfigMap을 참조합니다.
2
data.application.properties: 이 섹션에서는 애플리케이션과 함께 배포된 원래 application.properties 파일의 설정을 재정의할 수 있는 속성 설정을 나열합니다.
3
빠른 시작.recipients: 빠른 시작Configuration 빈의 수신자 속성에 삽입해야 합니다.

보기 권한 설정

Secret의 deployment.yml 파일에 표시된 대로 serviceAccountName 은 프로젝트의 deployment.yml 파일에서 qs-camel-config 로 설정됩니다. 따라서 빠른 시작 애플리케이션에 대한 보기 권한을 활성화하려면 다음 명령을 입력해야 합니다( test 프로젝트 네임스페이스에 배포한다고 가정).

oc policy add-role-to-user view system:serviceaccount:test:qs-camel-config
Copy to Clipboard Toggle word wrap

Spring Cloud Kubernetes 플러그인 구성

Spring Cloud Kubernetes 플러그인은 bootstrap.yml 파일의 다음 설정으로 구성됩니다.

spring.application.name
이 값은 ConfigMap 오브젝트의 metadata.name 과 일치해야 합니다(예: 빠른 시작 프로젝트의 sample-configmap.yml 에 정의된 대로). 기본값은 application 입니다.
spring.cloud.kubernetes.reload.enabled
이 값을 true 로 설정하면 ConfigMap 오브젝트를 동적으로 다시 로드할 수 있습니다.

지원되는 속성에 대한 자세한 내용은 PropertySource Reload Configuration Properties 을 참조하십시오.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat