DEV Community

Martin Mwangi
Martin Mwangi

Posted on

Infrastructure GitOps: A Step-by-Step Guide to Setting Up Your Test Cluster Locally using minikube for Seamless Exploration

Introduction

Explore the power of Crossplane Infrastructure through GitOps as I guide you in setting up a Crossplane Management Cluster on a local Minikube cluster. Follow this comprehensive tutorial to create and manage AWS resources seamlessly within your Kubernetes environment.

Prerequisites for setting up Crossplane

  • A Kubernetes cluster with at least 2 GB of RAM

  • Permissions to create pods and secrets in the Kubernetes cluster

  • Helm version v3.2.0 or later

  • An AWS account with permissions to create an S3 storage bucket

  • AWS access keys

Step 1: A Kubernetes cluster with at least 2 GB of RAM 
We will use Minikube to set up a Kubernetes cluster locally on Ubuntu - x86-64. If your setup is different, visit https://minikube.sigs.k8s.io/docs/start/ to download the binary.

Install the latest minikube stable release:

curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
Enter fullscreen mode Exit fullscreen mode

Start minikube:

minikube start
Enter fullscreen mode Exit fullscreen mode

Add the current user to the docker group and then start a new shell with the updated group membership using the command below

sudo usermod -aG docker $USER && newgrp docker
Enter fullscreen mode Exit fullscreen mode

If minikube fails to start, setup docker as your driver using the commands below:

Start a cluster using the docker driver:

minikube start --driver=docker
Enter fullscreen mode Exit fullscreen mode

To make docker the default driver

minikube config set driver docker
Enter fullscreen mode Exit fullscreen mode

Interact with the cluster:
If you already have kubectl installed to get pods

kubectl get po -A
Enter fullscreen mode Exit fullscreen mode

If you don’t have kubectl installed, use the command below to set it up and get pods:

minikube kubectl -- get po -A
Enter fullscreen mode Exit fullscreen mode

Step 2: Install Helm
Use the commands below to install helm locally using a bash script:

curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
Enter fullscreen mode Exit fullscreen mode

Step 3: Install Crossplane
Add the Crossplane Helm repository:

helm repo add crossplane-stable https://charts.crossplane.io/stable
Enter fullscreen mode Exit fullscreen mode

Update the local Helm chart cache:

helm repo update
Enter fullscreen mode Exit fullscreen mode

Install the Crossplane helm chart:

helm install crossplane \
--namespace crossplane-system \
--create-namespace crossplane-stable/crossplane
Enter fullscreen mode Exit fullscreen mode

Run the Helm dry-run to see all the Crossplane components Helm installs.

helm install crossplane \
crossplane-stable/crossplane \
--dry-run --debug \
--namespace crossplane-system \
--create-namespace
Enter fullscreen mode Exit fullscreen mode

Install the Crossplane components:

helm install crossplane \
crossplane-stable/crossplane \
--namespace crossplane-system \
--create-namespace
Enter fullscreen mode Exit fullscreen mode

Verify if Crossplane is installed:

kubectl get pods -n crossplane-system
Enter fullscreen mode Exit fullscreen mode

View all the end-points created when Crossplane is installed:

kubectl api-resources | grep crossplane
Enter fullscreen mode Exit fullscreen mode

Install the AWS provider
Install the AWS provider into the Kubernetes cluster with a Kubernetes configuration file. You can choose your provider based on the managed resource you want o provision. We will install AWS S3 provider which provisions S3 managed resource

cat <<EOF | kubectl apply -f -
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
  name: provider-aws-s3
spec:
  package: xpkg.upbound.io/upbound/provider-aws-s3:v0.37.0
EOF
Enter fullscreen mode Exit fullscreen mode

Verify the provider installed with kubectl get providers.

kubectl get providers
Enter fullscreen mode Exit fullscreen mode

Add your access key and secret to a text file aws-credentials.txt

[default]
aws_access_key_id = <access key>
aws_secret_access_key = <secret key>
Enter fullscreen mode Exit fullscreen mode

Create a Kubernetes secret with the AWS credentials

kubectl create secret \
generic aws-secret \
-n crossplane-system \
--from-file=creds=./aws-credentials.txt
Enter fullscreen mode Exit fullscreen mode

View kubernetes secret

kubectl describe secret aws-secret -n crossplane-system
Enter fullscreen mode Exit fullscreen mode

Create a ProviderConfig: a ProviderConfig customizes the settings of the AWS Provider. Apply the ProviderConfig with this Kubernetes configuration file:

cat <<EOF | kubectl apply -f -
apiVersion: aws.upbound.io/v1beta1
kind: ProviderConfig
metadata:
  name: default
spec:
  credentials:
    source: Secret
    secretRef:
      namespace: crossplane-system
      name: aws-secret
      key: creds
EOF
Enter fullscreen mode Exit fullscreen mode

Create a managed resource:

bucket=$(echo "crossplane-bucket-"$(head -n 4096 /dev/urandom | openssl sha1 | tail -c 10))
cat <<EOF | kubectl apply -f -
apiVersion: s3.aws.upbound.io/v1beta1
kind: Bucket
metadata:
  name: $bucket
spec:
  forProvider:
    region: us-east-2
  providerConfigRef:
    name: default
EOF
Enter fullscreen mode Exit fullscreen mode

A managed resource is anything Crossplane creates and manages outside of the Kubernetes cluster.
Verify crossplane has created an S3 bucket:

kubectl get buckets
Enter fullscreen mode Exit fullscreen mode

References

Top comments (0)