LoginSignup
1
0

More than 3 years have passed since last update.

Crossplane provider for IBM Cloud を使ってみる

Posted at

Crossplane infrastructure provider for IBM Cloudを使ってみます。対象はv0.1.1です。なお、Crossplaneはv1.0.0です。

Crossplaneとは

目的

kuberenetesのCustom resources definition (CRD)で様々なクラウドのリソースをkubectlコマンドにより宣言的に払い出し、管理します。Crossplaneでは払い出す環境をProviderといい、少なくともAWS、GCP、Azure、Alibabaが対応しています。それぞれのクラウドにあるデータベースやVPCを作成、管理できるだけでなく、 Open Application Model (OAM)を実装しアプリケーションも対応します(ただし現在アルファ機能)。なお、1つのAPIで様々なProviderに対応するのではなく、ProviderごとにAPIがあり、当然対応するリソースは異なるので注意が必要です(アプリケーションはその限りではない)。

開発状況

現在、Cloud Native Computing Foundation (CNCF) Sandbox プロジェクトです。Upboundが開発し公開しました。開発は現在に至るまで、ほぼUpboundにより行われています。他には、Alibaba、Qiniu、InfraCloud、Red Hat、Microsoftなどです。

Crossplane infrastructure provider for IBM Cloudとは

Crossplane infrastructure provider for IBM Cloudは、Crossplane communityによって管理されているオープンソースIBM Cloudに対応するCrossplaneのproviderです。

使ってみる

Docker Desktop WSL 2 backendを使って、Ubuntu 20.04で実行しました。

インストールと設定

Getting Started and Documentation に従います。

IBM Cloud CLIインストールと設定

IBM Cloud CLI の概説に従います。

コマンドを実行してIBM Cloud CLIをインストールします。

curl -sL https://raw.githubusercontent.com/IBM-Cloud/ibm-cloud-developer-tools/master/linux-installer/idt-installer | bash

IBMid を使用して IBM Cloud にログインします。 私はフェデレーテッド ID を使用してログインしました。

$ ibmcloud login --sso
(以降省略)

Crossplaneのインストール

Install Crossplaneに従います。Helmはインストール済であるとします。

$ kubectl create namespace crossplane-system
namespace/crossplane-system created
$ helm repo add crossplane-stable https://charts.crossplane.io/stable
"crossplane-stable" has been added to your repositories
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "crossplane-stable" chart repository
Update Complete. ⎈Happy Helming!⎈
$ helm install crossplane --namespace crossplane-system crossplane-stable/crossplane
NAME: crossplane
LAST DEPLOYED: Thu Jan 14 16:27:49 2021
NAMESPACE: crossplane-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
Release: crossplane

Chart Name: crossplane
Chart Description: Crossplane is an open source Kubernetes add-on that extends any cluster with the ability to provision and manage cloud infrastructure, services, and applications using kubectl, GitOps, or any tool that works with the Kubernetes API.
Chart Version: 1.0.0
Chart Application Version: 1.0.0

Kube Version: v1.19.3
$

Crossplaneの状態を確認します。

$ helm list -n crossplane-system
NAME            NAMESPACE               REVISION        UPDATED                                 STATUS          CHART                   APP VERSION
crossplane      crossplane-system       1               2021-01-14 16:27:49.2554043 +0900 JST   deployed        crossplane-1.0.0        1.0.0      

Install Crossplane CLIに従い、Crossplane CLIをインストールします。

$ curl -sL https://raw.githubusercontent.com/crossplane/crossplane/release-1.0/install.sh | sh
kubectl plugin downloaded successfully! Run the following commands to finish installing it:

sudo mv kubectl-crossplane /usr/local/bin
kubectl crossplane --help

Visit https://crossplane.io to get started. 🚀
Have a nice day! 👋

$
$ sudo mv kubectl-crossplane /usr/local/bin

IBM Cloud Providerのインストール

Install IBM Cloud Providerに従います。

$ kubectl crossplane install provider crossplane/provider-ibm-cloud:alpha
provider.pkg.crossplane.io/crossplane-provider-ibm-cloud created
$

IBM Cloud API Keyの生成

Generate IBM Cloud API Keyに従います。

$ if [[ -z "${IBMCLOUD_API_KEY}" ]]; then
>   echo "*** Generating new APIKey"
>   IBMCLOUD_API_KEY=$(ibmcloud iam api-key-create provider-ibm-cloud-key -d "Key for Crossplane Provider IBM Cloud" | grep "API Key" | awk '{ print $3 }')
> fi
*** Generating new APIKey
Please preserve the API key! It cannot be retrieved after it's created.
$

Provider Secret生成

Create a Provider Secretに従います。

$ kubectl create secret generic provider-ibm-cloud-secret --from-literal=credentials=${IBMCLOUD_API_KEY} -n crossplane-system
secret/provider-ibm-cloud-secret created
$

Providerの設定

Configure the Providerに従います。

$ cat <<EOF | kubectl apply -f -
> apiVersion: ibm-cloud.crossplane.io/v1beta1
> kind: ProviderConfig
> metadata:
>   name: ibm-cloud
> spec:
>   credentials:
>     source: Secret
>     secretRef:
>       namespace: crossplane-system
>       name: provider-ibm-cloud-secret
>       key: credentials
>   region: us-south
> EOF
providerconfig.ibm-cloud.crossplane.io/ibm-cloud created
$

作成されたことを確認します。

$ kubectl get providerconfig
NAME        PROJECT-ID   AGE
ibm-cloud                67s
$

リソースを利用する

それでは実際に使ってみます。v0.1.1 ではまだリソースを作成することができず、すでに作成されたリソースをCrossplaneにインポートすることしかできません。PostgreSQLの例をただ実行しても何も怒らないので注意が必要です。

以降の手順はResource Controller V2 API examplesに従います。

作成するリソースはなんでもいいですが、CrossplaneのサイトではPostgreSQLを作成する例が載っているため、ここでもPosgreSQLを作成します。

IBM Cloud Catalogから作成します。

作成した後、状態がactiveとなったことを確認します。xxxxxxxxは実際のアカウント名です。

$ ibmcloud resource service-instances
Retrieving instances with type service_instance in all resource groups in all locations under account xxxxxxxx...
OK
Name                              Location   State    Type   
Databases for PostgreSQL-z5       us-south   active   service_instance   
$

マニフェストファイルに埋め込むための環境変数を設定します。

$ NAME="Databases for PostgreSQL-z5"
$ INFO="$(ibmcloud resource service-instance "${NAME")"}')
$ ID=$(echo "$INFO" | grep ^ID | awk '{print $2}')
$ TARGET=$(echo "$INFO" | grep ^Location | awk '{print $2}')
$ SERVICE_NAME=$(echo "$INFO" | grep "^Service Name" | awk '{print $3}')
$ RG_NAME=$(echo "$INFO" | grep "^Resource Group Name" | awk '{print $4}')
$ RP_NAME=$(echo "$INFO" | grep "^Service Plan Name" | awk '{print $4}')
$ META_NAME=$(echo "$NAME" | awk '{print tolower($0)}' | tr " " - | tr "." -)
$

マニフェストファイルを適用します。

$ cat <<EOF | kubectl apply -f -
> apiVersion: resourcecontrollerv2.ibm-cloud.crossplane.io/v1alpha1
> kind: ResourceInstance
> metadata:
>   name: $META_NAME
>   annotations:
>     crossplane.io/external-name: "$ID"
> spec:
>   forProvider:
>     name: $NAME
>     target: $TARGET
>     resourceGroupName: $RG_NAME
>     serviceName: $SERVICE_NAME
>     resourcePlanName: $RP_NAME
>   providerConfigRef:
>     name: ibm-cloud
> EOF
resourceinstance.resourcecontrollerv2.ibm-cloud.crossplane.io/databases-for-postgresql-z5 created
$ 

リソースが作成されたことを確認します。

$ kubectl get resourceinstance
NAME                          STATUS   STATE    CLASS   AGE
databases-for-postgresql-z5            active           35s
$

ただ表示されただけじゃないのか?と思ったので、削除してみます。

$ kubectl delete resourceinstance databases-for-postgresql-z5
resourceinstance.resourcecontrollerv2.ibm-cloud.crossplane.io "databases-for-postgresql-z5" deleted
$ kubectl get resourceinstance
No resources found

Crossplane上は削除されたようです。

実際に削除されたことを確認します。

$ ibmcloud resource service-instances
Retrieving instances with type service_instance in all resource groups in all locations under account xxxxxxxx...
OK
No service instance found.
$

確かに削除されていました。

所感

リソースを作成できず驚きました。今後に期待しましょう。。

参考

1
0
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
1
0