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 파일에 추가합니다.
절차
-
프로젝트의
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>
fabric8 karaf 기능은 Karaf 서버에 설치됩니다.
12.4.2. Fabric8 Karaf Core 번들 기능 추가 링크 복사링크가 클립보드에 복사되었습니다!
번들 fabric8-karaf-core 는 청사진 및 ConfigAdmin 확장에서 사용하는 기능을 제공합니다.
절차
프로젝트의
pom.xml을 열고fabric8-karaf-core를startupFures 섹션에추가합니다.<startupFeatures> ... <feature>fabric8-karaf-core</feature> ... </startupFeatures>이렇게 하면 사용자 정의 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);
}
platform holderResolver 서비스는 다른 속성 자리 표시자 해상도 전략의 수집기 역할을 합니다. 기본적으로 제공되는 해결 전략은 표 Resolution Strategies 에 나열되어 있습니다. 속성 자리 표시자 서비스 옵션을 설정하려면 시스템 속성 또는 환경 변수 또는 둘 다를 사용할 수 있습니다.
절차
OpenShift에서 ConfigMap에 액세스하려면 서비스 계정에 보기 권한이 필요합니다. 서비스 계정에 보기 권한을 추가합니다.
oc policy add-role-to-user view system:serviceaccount:$(oc project -q):default -n $(oc project -q)- API를 통해 보안에 대한 액세스 권한이 제한될 수 있으므로 Pod에 보안을 마운트합니다.
볼륨 마운트로 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
12.4.4. 사용자 정의 속성 자리 표시자 확인자 추가 링크 복사링크가 클립보드에 복사되었습니다!
사용자 정의 암호화와 같은 특정 요구 사항을 지원하기 위해 사용자 정의 자리 표시자 확인자를 추가할 수 있습니다. 또한 placesholder Resolver 서비스를 사용하여 해결자를 청사진 및 ConfigAdmin에서 사용할 수 있도록 할 수 있습니다.
절차
pom.xml프로젝트에 다음 mvn 종속성을 추가합니다.pom.xml
--- <dependency> <groupId>io.fabric8</groupId> <artifactId>fabric8-karaf-core</artifactId> </dependency> ---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; } }다음과 같이 구성 관리에서 해결 프로그램을 참조할 수 있습니다.
속성
my.property = $[myResolver:value-to-resolve]
12.4.5. 해결 전략 목록 링크 복사링크가 클립보드에 복사되었습니다!
platform holderResolver 서비스는 다른 속성 자리 표시자 해상도 전략의 수집기 역할을 합니다. 기본적으로 제공하는 해결 전략은 표에 나열되어 있습니다.
- 해결 전략 목록
| 접두사 | 예제 | 설명 |
|
|
| OS 환경 변수에서 속성을 조회합니다. |
| 'sys |
| Java JVM 시스템 속성에서 속성을 조회합니다. |
| `service |
| 서비스 이름 지정 규칙을 사용하여 OS 환경 변수에서 속성을 조회합니다. |
|
|
| hostname 부분만 반환하는 서비스 이름 지정 규칙을 사용하여 OS 환경 변수에서 속성을 찾습니다. |
|
|
| 포트 부분만 반환하는 서비스 이름 규칙을 사용하여 OS 환경 변수에서 속성을 찾습니다. |
|
|
| Kubernetes ConfigMap (API를 통해)에서 속성 조회 |
|
|
| Kubernetes 보안 (API 또는 볼륨 마운트를 통해)에서 속성 조회 |
12.4.6. Property placesholder 서비스 옵션 목록 링크 복사링크가 클립보드에 복사되었습니다!
속성 자리 표시자 서비스는 다음 옵션을 지원합니다.
- 속성 자리 표시자 서비스 옵션 목록
| 이름 | 기본 | 설명 |
|---|---|---|
|
| $[ | 자리 표시자의 접두사 |
|
| ] | 자리 표시자의 접미사입니다. |
|
| null | 시크릿이 매핑되는 쉼표로 구분된 경로 목록 |
|
| false | API를 통해 시크릿 사용/비활성화 |