2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Crossplane Provider for Oracle Cloud Infrastructure (OCI) 入門

2
Posted at

初めに

この記事では、Crossplane Provider for Oracle Cloud Infrastructure (OCI) を使って、Kubernetes から OCI リソース(例:Object Storage Bucket)を管理する方法を紹介します。

公式 GitHub リポジトリはこちらです:

本記事では Quick Start をベースに、インストール → 設定 → リソース作成 → 削除 まで一連の流れを確認します。


Crossplane とは?

Crossplane は Kubernetes 上で動作する Control Plane で、クラウドリソースを Kubernetes の CRD(Custom Resource)として宣言的に管理できる仕組みです。

Terraform に近いことができますが、以下の点が特徴です。

  • Kubernetes ネイティブ(kubectl / GitOps と相性が良い)
  • 複数クラウドを同一の操作感で管理可能
  • プラットフォームエンジニアリング向けの拡張性

OCI 公式の Provider が提供されているため、OCI 環境でも安心して利用できます。


Helm のインストール(公式スクリプト・推奨)

まずは Helm をインストールします。

curl -fsSL https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3 | bash

helm version

Crossplane のインストール

Crossplane は Kubernetes クラスタ上にインストールします。事前に kubectl context が正しいクラスタを向いていることを確認してください。

Namespace 作成

kubectl create namespace crossplane-system

Helm Repository 追加

helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update

Crossplane インストール

helm install crossplane \
  --namespace crossplane-system \
  crossplane-stable/crossplane

動作確認

helm list -n crossplane-system
kubectl get all -n crossplane-system

OCI Provider Family のインストール

OCI の公式 Provider は provider-family という仕組みを採用しています。

ポイント

  • 必ず family provider を先にインストールする
  • 命名規則:oracle-provider-family-oci
  • sub-provider(例:Object Storage)は family provider に依存

Provider のインストール

cat <<EOF | kubectl apply -f -
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
  name: oracle-provider-family-oci
spec:
  package: ghcr.io/oracle/provider-family-oci:v0.1.0
---
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
  name: provider-oci-objectstorage
spec:
  package: ghcr.io/oracle/provider-oci-objectstorage:v0.1.0
EOF
kubectl get providers

HEALTHY になるまで最大で 5 分ほどかかる場合があります。


OCI 認証情報(Secret)の作成

OCI Provider を使うには、OCI API Key 認証情報が必要です。

Secret 作成(マスク済み)

kubectl create secret generic oci-creds \
  --namespace=crossplane-system \
  --from-literal=credentials='{
    "tenancy_ocid": "ocid1.tenancy.oc1..***MASKED***",
    "user_ocid": "ocid1.user.oc1..***MASKED***",
    "private_key": "-----BEGIN RSA PRIVATE KEY-----\n***MASKED***\n-----END RSA PRIVATE KEY-----\nOCI_API_KEY\n",
    "fingerprint": "**:**:**:**:**",
    "region": "ap-****-1",
    "auth": "ApiKey"
  }'

Private Key の整形

OCI CLI で生成した秘密鍵は、以下のコマンドで 1 行ずつ整形できます。

awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' ~/.oci/oci_api_key.pem

⚠️ 秘密鍵の最後に OCI_API_KEY を含む行を追加することが必須です。


ProviderConfig の登録

作成した Secret を参照する ProviderConfig を作成します。

cat <<EOF | kubectl apply -f - 
apiVersion: oci.upbound.io/v1beta1
kind: ProviderConfig
metadata:
  name: default
spec:
  credentials:
    source: Secret
    secretRef:
      name: oci-creds
      namespace: crossplane-system
      key: credentials
EOF
kubectl get providerconfig

マネージドリソースの作成(Object Storage Bucket)

例として、OCI Object Storage Bucket を作成します。

例として、OCI Object Storage Bucket を作成します。

cat <<EOF | kubectl apply -f -
apiVersion: objectstorage.oci.upbound.io/v1alpha1
kind: Bucket
metadata:
  labels:
    testing.upbound.io/example-name: bucket_label_1
  name: bucket1
spec:
  forProvider:
    compartmentId: ocid1.compartment.oc1..***MASKED***
    name: bucket1
    namespace: ***MASKED***
EOF

状態確認

kubectl get managed
NAME                                          SYNCED   READY   EXTERNAL-NAME
bucket.objectstorage.oci.upbound.io/bucket1   True     True    n/***MASKED***/b/bucket1
  • READY=True
  • SYNCED=True

であれば、OCI 側に Bucket が正常に作成されています。


リソース削除

マネージドリソース削除

cat <<EOF | kubectl delete -f -
apiVersion: objectstorage.oci.upbound.io/v1alpha1
kind: Bucket
metadata:
  name: bucket1
EOF

kubectl get buckets

⚠️ Provider を削除する前に、必ずマネージドリソースを削除してください


Provider の削除

kubectl delete providers/provider-oci-objectstorage
kubectl delete providerconfig/default
kubectl delete providers/oracle-provider-family-oci

まとめ

  • Crossplane を使うと OCI リソースを Kubernetes から宣言的に管理できる
  • OCI 公式 Provider Family により安心して利用可能
  • GitOps / Platform Engineering と非常に相性が良い

今後は Compute、Network、Database など他の OCI Provider も試していくと、より強力な運用が可能になります。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?