12.4. Fabric8 Karaf 기능 사용


Fabric8은 Apache Karaf를 지원하여 Kubernetes용 OSGi 앱을 보다 쉽게 개발할 수 있습니다.

Fabric8의 중요한 기능은 다음과 같습니다.

  • Blueprint XML 파일에서 자리 표시자를 해결하기 위한 다양한 전략
  • 환경 변수
  • 시스템 속성
  • 서비스
  • Kubernetes ConfigMap
  • Kubernetes Secrets
  • Kubernetes 구성 맵을 사용하여 OSGi 구성 관리를 동적으로 업데이트합니다.
  • Kubernetes heath에서 OSGi 서비스에 대한 heath 검사를 제공합니다.

12.4.1. Fabric8 Karaf 기능 추가

기능을 사용하려면 fabric8-karaf-features 종속성을 프로젝트 POM 파일에 추가합니다.

절차

  1. 프로젝트의 pom.xml 파일을 열고 fabric8-karaf-features 종속성을 추가합니다.
<dependency>
  <groupId>io.fabric8</groupId>
  <artifactId>fabric8-karaf-features</artifactId>
  <version>${fabric8.version}</version>
  <classifier>features</classifier>
  <type>xml</type>
</dependency>
Copy to Clipboard Toggle word wrap

fabric8 karaf 기능은 Karaf 서버에 설치됩니다.

12.4.2. Fabric8 Karaf Core 번들 기능 추가

번들 fabric8-karaf-core 는 청사진 및 ConfigAdmin 확장에서 사용하는 기능을 제공합니다.

절차

  1. 프로젝트의 pom.xml 을 열고 fabric8-karaf-corestartupFures 섹션에 추가합니다.

    <startupFeatures>
      ...
      <feature>fabric8-karaf-core</feature>
      ...
    </startupFeatures>
    Copy to Clipboard Toggle word wrap

    이렇게 하면 사용자 정의 Karaf 배포에서 fabric8-karaf-core 기능이 추가됩니다.

12.4.3. Property placesholder 서비스 옵션 설정

번들 fabric8-karaf-core 는 다음과 같은 인터페이스를 사용하여 서비스 platformholderResolver 를 내보냅니다.

public interface PlaceholderResolver {
    /**
     * Resolve a placeholder using the strategy indicated by the prefix
     *
     * @param value the placeholder to resolve
     * @return the resolved value or null if not resolved
     */
    String resolve(String value);

    /**
     * Replaces all the occurrences of variables with their matching values from the resolver using the given source string as a template.
     *
     * @param source the string to replace in
     * @return the result of the replace operation
     */
    String replace(String value);

    /**
     * Replaces all the occurrences of variables within the given source builder with their matching values from the resolver.
     *
     * @param value the builder to replace in
     * @rerurn true if altered
     */
    boolean replaceIn(StringBuilder value);

    /**
     * Replaces all the occurrences of variables within the given dictionary
     *
     * @param dictionary the dictionary to replace in
     * @rerurn true if altered
     */
    boolean replaceAll(Dictionary<String, Object> dictionary);

    /**
     * Replaces all the occurrences of variables within the given dictionary
     *
     * @param dictionary the dictionary to replace in
     * @rerurn true if altered
     */
    boolean replaceAll(Map<String, Object> dictionary);
}
Copy to Clipboard Toggle word wrap

platform holderResolver 서비스는 다른 속성 자리 표시자 해상도 전략의 수집기 역할을 합니다. 기본적으로 제공되는 해결 전략은 표 Resolution Strategies 에 나열되어 있습니다. 속성 자리 표시자 서비스 옵션을 설정하려면 시스템 속성 또는 환경 변수 또는 둘 다를 사용할 수 있습니다.

절차

  1. OpenShift에서 ConfigMap에 액세스하려면 서비스 계정에 보기 권한이 필요합니다. 서비스 계정에 보기 권한을 추가합니다.

    oc policy add-role-to-user view system:serviceaccount:$(oc project -q):default -n $(oc project -q)
    Copy to Clipboard Toggle word wrap
  2. API를 통해 보안에 대한 액세스 권한이 제한될 수 있으므로 Pod에 보안을 마운트합니다.
  3. 볼륨 마운트로 Pod에서 사용 가능한 보안은 다음과 같이 보안이라는 디렉터리에 매핑됩니다.

    containers:
      -
       env:
       - name: FABRIC8_K8S_SECRETS_PATH
         value: /etc/secrets
         volumeMounts:
       - name: activemq-secret-volume
         mountPath: /etc/secrets/activemq
         readOnly: true
       - name: postgres-secret-volume
         mountPath: /etc/secrets/postgres
         readOnly: true
    
    volumes:
      - name: activemq-secret-volume
      secret:
      secretName: activemq
      - name: postgres-secret-volume
       secret:
      secretName: postgres
    Copy to Clipboard Toggle word wrap

12.4.4. 사용자 정의 속성 자리 표시자 확인자 추가

사용자 정의 암호화와 같은 특정 요구 사항을 지원하기 위해 사용자 정의 자리 표시자 확인자를 추가할 수 있습니다. 또한 placesholder Resolver 서비스를 사용하여 해결자를 청사진 및 ConfigAdmin에서 사용할 수 있도록 할 수 있습니다.

절차

  1. pom.xml 프로젝트에 다음 mvn 종속성을 추가합니다.

    pom.xml

    ---
    <dependency>
      <groupId>io.fabric8</groupId>
      <artifactId>fabric8-karaf-core</artifactId>
    </dependency>
    ---
    Copy to Clipboard Toggle word wrap

  2. PropertiesFunction 인터페이스를 구현하고 SCR을 사용하여 OSGi 서비스로 등록합니다.

    import io.fabric8.karaf.core.properties.function.PropertiesFunction;
    import org.apache.felix.scr.annotations.Component;
    import org.apache.felix.scr.annotations.ConfigurationPolicy;
    import org.apache.felix.scr.annotations.Service;
    
    @Component(
        immediate = true,
        policy = ConfigurationPolicy.IGNORE,
        createPid = false
    )
    @Service(PropertiesFunction.class)
    public class MyPropertiesFunction implements PropertiesFunction {
        @Override
        public String getName() {
            return "myResolver";
        }
    
        @Override
        public String apply(String remainder) {
            // Parse and resolve remainder
            return remainder;
        }
    }
    Copy to Clipboard Toggle word wrap
  3. 다음과 같이 구성 관리에서 해결 프로그램을 참조할 수 있습니다.

    속성

    my.property = $[myResolver:value-to-resolve]
    Copy to Clipboard Toggle word wrap

12.4.5. 해결 전략 목록

platform holderResolver 서비스는 다른 속성 자리 표시자 해상도 전략의 수집기 역할을 합니다. 기본적으로 제공하는 해결 전략은 표에 나열되어 있습니다.

  1. 해결 전략 목록
Expand

접두사

예제

설명

env

env:JAVA_HOME

OS 환경 변수에서 속성을 조회합니다.

'sys

sys:java.version

Java JVM 시스템 속성에서 속성을 조회합니다.

`service

service:amq

서비스 이름 지정 규칙을 사용하여 OS 환경 변수에서 속성을 조회합니다.

service.host

service.host:amq

hostname 부분만 반환하는 서비스 이름 지정 규칙을 사용하여 OS 환경 변수에서 속성을 찾습니다.

service.port

service.port:amq

포트 부분만 반환하는 서비스 이름 규칙을 사용하여 OS 환경 변수에서 속성을 찾습니다.

k8s:map

k8s:map:myMap/myKey

Kubernetes ConfigMap (API를 통해)에서 속성 조회

k8s:secret

k8s:secret:amq/password

Kubernetes 보안 (API 또는 볼륨 마운트를 통해)에서 속성 조회

12.4.6. Property placesholder 서비스 옵션 목록

속성 자리 표시자 서비스는 다음 옵션을 지원합니다.

  1. 속성 자리 표시자 서비스 옵션 목록
Expand
이름기본설명

fabric8.placeholder.prefix

$[

자리 표시자의 접두사

fabric8.placeholder.suffix

]

자리 표시자의 접미사입니다.

fabric8.k8s.secrets.path

null

시크릿이 매핑되는 쉼표로 구분된 경로 목록

fabric8.k8s.secrets.api.enabled

false

API를 통해 시크릿 사용/비활성화

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

Theme

© 2025 Red Hat