Crossplane Provider IONOS Cloud Usage Example
Overview
Crossplane allows the user to manage infrastructure directly from Kubernetes. Crossplane extends a Kubernetes cluster to support orchestrating any infrastructure or managed service. Providers extend Crossplane to enable infrastructure resource provisioning of specific APIs.
Crossplane Provider IONOS Cloud contains a Controller and Custom Resource Definitions(CRDs). The CRDs are defined in sync with the API and contain the desired state. The Controller has a reconcile loop, and it constantly compares the desired state vs the actual state and takes action to reach the desired state. Using the SDK Go, the Controller performs CRUD operations and resources are managed in the IONOS Cloud.
In this Proof of Concept of the IONOS Cloud Provider, we will create a DBaaS Postgres cluster resource in the IONOS Cloud.
Prerequisites
Ensure that you have the following:
A Kubernetes implementation, such as
kindDocker
Credentials to access IONOS Cloud
Clone this repository locally to be able to run examples
Check prerequisites
You can now check your prerequisites. To check K8s, in case of using kind, run the following command:
kind versionTo check the credentials, run the following command:
export IONOS_USERNAME=xxx
export IONOS_PASSWORD=xxx
export BASE64_PW=$(echo -n "${IONOS_PASSWORD}" | base64)OR
export IONOS_TOKEN=xxxTo clone the repository locally, run the following command:
git clone https://github.com/ionos-cloud/crossplane-provider-ionoscloud.git
cd crossplane-provider-ionoscloudSet up Crossplane Provider IONOS Cloud
To set up Crossplane Provider IONOS Cloud, follow these steps:
Create a K8s cluster (in case of using kind)
To create a cluster in case of using kind, run the following command:
kind create cluster --name crossplane-example
kubectl config use-context kind-crossplane-exampleCreate namespace for the crossplane ecosystem
To create namespace for the crossplane ecosystem, run the following command:
kubectl create namespace crossplane-systemInstall Crossplane via helm
To create a cluster in case of using helm, run the following command:
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
helm install crossplane --namespace crossplane-system crossplane-stable/crossplaneRegister CRDs into k8s cluster
To register CRDs into k8s cluster, run the following command:
kubectl apply -f package/crds/ -RInstall ProviderConfig for credentials
To install ProviderConfig for credentials, run the following commands:
export BASE64_PW=$(echo -n "${IONOS_PASSWORD}" | base64)
kubectl create secret generic --namespace crossplane-system example-provider-secret --from-literal=credentials="{\"user\":\"${IONOS_USERNAME}\",\"password\":\"${BASE64_PW}\"}"
kubectl apply -f examples/provider/config.yamlOR
kubectl create secret generic --namespace crossplane-system example-provider-secret --from-literal=credentials="{\"token\":\"${IONOS_TOKEN}\"}"
kubectl apply -f examples/provider/config.yamlInstall Crossplane Provider for IONOS Cloud
To install Crossplane Provider for IONOS Cloud, run the following command:
kubectl apply -f examples/provider/install-provider.yamlYou can install other providers, such as Helm and Kubernetes, using the following:
kubectl apply --namespace crossplane-system -f examples/providers/other-providers.yamlCheck the health of Crossplane Provider IONOS Cloud
To check if the Crossplane Provider IONOS Cloud is installed and healthy, run the following command:
kubectl get providersYou should be able to see pods running in the crossplane-system namespace for each provider installed. To see the existing pods from all namespaces, run kubectl get pods -A.
Run the following command to see the pods:
kubectl get pods -n crossplane-system Result: Your output will be:
NAME READY STATUS RESTARTS AGE
crossplane-5b6896bb4c-nq5tl 1/1 Running 0 66m
crossplane-rbac-manager-7874897d59-skdtt 1/1 Running 0 66m
provider-helm-a7f79daa3799-78d5959d6d-rktfs 1/1 Running 0 65m
provider-ionos-cf2fec81b474-54f5d7ddd4-w9w9h 1/1 Running 0 66m
provider-kubernetes-df601dea646a-84f7d6db54-t5dn5 1/1 Running 0 65mCheck CRDs
To check the CRDs, run the following command:
kubectl get crds | grep ionoscloudA CRD named postgresclusters.dbaas.ionoscloud.crossplane.io should be displayed in the output.
After that, you can create a Custom Resource (CR) of type postgresclusters.dbaas.ionoscloud.crossplane.io to provision a DBaaS Postgres cluster in the IONOS Cloud.
Provision DBaaS Postgres cluster
For the DBaaS Postgres service, there is only cluster resource available into the Crossplane Provider IONOS Cloud.
Warning: Before running the next command, make sure to update the values in the examples/ionoscloud/dbaas/postgres-cluster.yaml file. Look for spec.forProvider fields. It is required to specify the data center (via ID or via reference),LAN (via ID or via reference), CIDR, and location(in sync with the datacenter) and also credentials for the database user.
Create a Data Center CR, LAN CR, and Postgres cluster CR
To create a data center CR, LAN CR, and Postgres cluster CR, run the following command:
kubectl apply -f examples/ionoscloud/dbaas/postgres-cluster.yamlGet a Data Center CR, LAN CR, and Postgres cluster CR
To check if the created Postgres cluster CR is synced and ready, run the following command:
kubectl get postgresclustersResult: Your output will be:
NAME READY SYNCED CLUSTER ID STATE AGE
example True True 9b25ecab-83fe-11ec-8d97-828542a828c7 AVAILABLE 93mTo view more details, run the following command:
kubectl get postgresclusters -o wideThe external-name of the CR is the Cluster ID from IONOS Cloud. The cluster CR will be marked as ready when the cluster is in available state.
You can check if the DBaaS Postgres cluster was created in the IONOS Cloud using ionosctl latest versions. Run the following command:
ionosctl dbaas postgres cluster listResult: Your output will be:
ClusterId DisplayName Location DatacenterId LanId Cidr Instances State
9b25ecab-83fe-11ec-8d97-828542a828c7 testDemo de/txl 21d8fd28-5d62-43e9-a67b-68e52dac8885 1 192.168.1.100/24 1 AVAILABLEIn the DCD, go to the Menu > Databases > Postgres clusters.
Check if the data center and LAN CRs are created using:
kubectl get datacenters
kubectl get lansUpdate a Data Center CR, LAN and Postgres ccuster CR
If you want to update the CRs created, update values from the examples/ionoscloud/dbaas/postgres-cluster.yaml file using the following command:
kubectl apply -f examples/ionoscloud/dbaas/postgres-cluster.yamlThe updates applied should be updated in the external resource in IONOS Cloud.
Delete a Data Center CR, LAN and Postgres cluster CRs
To delete the Postgres cluster CR with the name example, use the following command:
kubectl delete postgrescluster exampleThis would trigger the destroying of the DBaaS Postgres cluster.
Warning: Make sure to delete the DBaaS Postgres cluster before deleting the data center or the LAN used in the Cluster's connection.
Delete the LAN and data center CRs using:
kubectl delete lan examplelan
kubectl delete datacenter exampleOR
You can use the following command
kubectl delete -f examples/ionoscloud/dbaas/postgres-cluster.yamlWarning: This command is not recommended and can be used for this particular case only. It might delete the data center before the cluster.
Summary
Refer to the following tables for DBaaS Postgres resources commands:
Custom Resource
Create/Delete/Update
DBaaS Postgres cluster
kubectl apply -f examples/ionoscloud/dbaas/postgres-cluster.yamlCustom Resource
GET
GET More Details
JSON Output
DBaaS Postgres cluster
kubectl get postgresclusterskubectl get postgresclusters -o widekubectl get postgresclusters -o jsonFor more information on all Managed Resources of Crossplane Provider IONOS Cloud, see Provision Resources on IONOS Cloud.
Uninstallation
To uninstall, you need to follow these steps:
Uninstall the Provider
After deleting all resources, it is safe to uninstall the Crossplane Provider IONOS Cloud. Run the following command:
kubectl delete -f examples/provider/config.yamlNow it is safe to delete also the Provider. The ProviderRevision will be deleted automatically using:
kubectl delete -f examples/provider/install-provider.yamlUninstall K8s cluster
Use the following command to delete the k8s cluster:
kind delete cluster --name crossplane-exampleResult: This way you can create and then delete the DBaaS Postgres cluster resource in the IONOS Cloud.
Last updated
