Crossplane brings the management of external resources into kubernetes through kubernetes APIs. This can in some situations be an alternative to other IaC such as terraform.
In the example below, we will create a droplet on DO by applying a kubernetes manifest using kubectl.
The exemple suppose the kubernetes cluster in which crossplane will be installed is already up.
```bash
kubectl create namespace crossplane-system
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
# install crossplane
helm install crossplane --namespace crossplane-system crossplane-stable/crossplane
# install the upjet digital ocean provider
cat <<EOF | kubectl apply -f -
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: provider-upjet-digitalocean
spec:
package: crossplane-contrib/provider-upjet-digitalocean:v0.3.0
EOF
# create the upjet digital ocean provider secret
kubectl apply -f - <<EOF
apiVersion: v1
kind: Secret
metadata:
namespace: crossplane-system
name: upjet-digitalocean-creds
type: Opaque
data:
credentials: "$(echo -n '{"token":"dop_v1_***"}' | base64)" # provide the DO token
EOF
# create the upjet digital ocean config
kubectl apply -f - <<EOF
apiVersion: digitalocean.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
name: do-upjet
spec:
credentials:
source: Secret
secretRef:
namespace: crossplane-system
name: upjet-digitalocean-creds
key: credentials
EOF
# create a droplet to test
kubectl apply -f - <<EOF
apiVersion: droplet.digitalocean.crossplane.io/v1alpha1
kind: Droplet
metadata:
name: example-droplet
spec:
forProvider:
name: example-droplet # This is required!
region: nyc3
size: s-1vcpu-1gb
image: ubuntu-20-04-x64
sshKeys: [] # Optional: Add your SSH key fingerprint(s)
backups: false
ipv6: false
monitoring: false
tags: ["crossplane", "demo"]
providerConfigRef:
name: do-upjet
EOF
Commentaires