新着:プロジェクトの最新情報はこちらで入手できますTwitterMastodon

ネームスペース間でのシークレット同期

単一の証明書によって作成された同じシークレットを、名前空間を跨いでの複数のコンポーネントで利用する必要がある場合があります。これを行うための推奨方法は、以下のような拡張機能を使用することです。

異なる名前空間のIngressリソースへのワイルドカードの提供(デフォルトSSL証明書)

ingress-nginxTraefikKongなど、ほとんどのIngressコントローラは、TLSを要求するがtls.[].secretNameを指定しないIngressリソースに使用する単一の証明書の指定をサポートしています。これは、多くの場合「デフォルトSSL証明書」と呼ばれます。これが正しく設定されている限り、任意の名前空間内のIngressリソースは単一のワイルドカード証明書を使用できます。ワイルドカード証明書はHTTP01検証ではサポートされておらず、DNS01が必要です。

Ingressスニペット例

apiVersion: networking.k8s.io/v1
kind: Ingress
#[...]
spec:
rules:
- host: service.example.com
#[...]
tls:
- hosts:
- service.example.com
#secretName omitted to use default wildcard certificate

拡張機能を使用した名前空間間での任意のシークレットの同期

ターゲットシークレットを同期するには、secretTemplateフィールドを使用して、拡張機能固有の注釈で生成されたシークレットに注釈を付けることができます(CertificateSecretTemplateを参照)。

reflectorの使用

以下の例は、cert-manager名前空間から複数の名前空間(例:devstagingprod)に証明書のシークレットを同期する方法を示しています。Reflectorは、許可された条件(正規表現サポート付き)に一致する名前空間(既存のものと新規のもの)に証明書のシークレットのコピーが提供され、最新の状態に維持されるようにします。また、reflectorを使用して他のシークレット(異なる名前)も同期できます(拡張機能のREADMEを参照)。

---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: source
namespace: cert-manager
spec:
secretName: source-tls
commonName: source
issuerRef:
name: source-ca
kind: Issuer
group: cert-manager.io
secretTemplate:
annotations:
reflector.v1.k8s.emberstack.com/reflection-allowed: "true"
reflector.v1.k8s.emberstack.com/reflection-allowed-namespaces: "dev,staging,prod" # Control destination namespaces
reflector.v1.k8s.emberstack.com/reflection-auto-enabled: "true" # Auto create reflection for matching namespaces
reflector.v1.k8s.emberstack.com/reflection-auto-namespaces: "dev,staging,prod" # Control auto-reflection namespaces

kubernetes-replicatorの使用

Replicatorは、プッシュベースとプルベースの両方のレプリケーションをサポートしています。プッシュベースのレプリケーションは、新しい名前空間が作成された場合、またはシークレットが変更された場合に、TLSシークレットを名前空間に「プッシュアウト」します。プルベースのレプリケーションでは、宛先名前空間に空のTLSシークレットを作成し、データがレプリケートされる「ソース」リソースを選択できます。次の例は、プルベースのアプローチを示しています。

apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: source
namespace: cert-manager
spec:
secretName: source-tls
commonName: source
issuerRef:
name: source-ca
kind: Issuer
secretTemplate:
annotations:
replicator.v1.mittwald.de/replication-allowed: "true" # permit replication
replicator.v1.mittwald.de/replication-allowed-namespaces: "dev,test,prod-[0-9]*" # comma separated list of namespaces or regular expressions
---
apiVersion: v1
kind: Secret
metadata:
name: tls-secret-replica
namespace: prod-1
annotations:
replicator.v1.mittwald.de/replicate-from: cert-manager/source-tls
type: kubernetes.io/tls
# Normally, we'd create an empty destination secret, but secrets of type
# 'kubernetes.io/tls' are treated in a special way and need to have properties
# data["tls.crt"] and data["tls.key"] to begin with, though they may be empty.
data:
tls.key: ""
tls.crt: ""