PART 6: HANDS-ON LABS
Lab 1: Deploy vCluster on Kubernetes
bash
# Install vCluster CLI
curl -L -o vcluster https://github.com/loft-sh/vcluster/releases/latest/download/vcluster-linux-amd64
chmod +x vcluster
sudo mv vcluster /usr/local/bin/
# Create a vCluster
vcluster create my-vcluster
# Connect to it
vcluster connect my-vcluster
# You now have a virtual cluster
kubectl get namespaces
kubectl get nodes
# Disconnect
vcluster disconnect
# Cleanup
vcluster delete my-vcluster
Lab 2: Multi-Tenancy with Capsule
bash
# Install Capsule
helm repo add projectcapsule https://projectcapsule.github.io/charts
helm install capsule projectcapsule/capsule -n capsule-system --create-namespace
# Create a Tenant
cat <<'EOF' | kubectl apply -f -
apiVersion: capsule.clastix.io/v1beta2
kind: Tenant
metadata:
name: team-a
spec:
owners:
- name: alice
kind: User
namespaceOptions:
quota: 5
resourceQuotas:
items:
- hard:
requests.cpu: "100"
requests.memory: 200Gi
limits.cpu: "200"
limits.memory: 400Gi
EOF
# Verify
kubectl get tenants
kubectl get namespaces -l capsule.clastix.io/tenant=team-a
Lab 3: Provision a Cluster with Cluster API
bash
# Install clusterctl
curl -L https://github.com/kubernetes-sigs/cluster-api/releases/download/v1.12.0/clusterctl-linux-amd64 -o clusterctl
chmod +x clusterctl
sudo mv clusterctl /usr/local/bin/
# Initialize management cluster
clusterctl init --infrastructure aws
# Generate cluster config
clusterctl generate cluster production \
--kubernetes-version v1.36.0 \
--control-plane-machine-count 3 \
--worker-machine-count 3 \
> production.yaml
# Apply
kubectl apply -f production.yaml
# Check status
clusterctl describe cluster production
kubectl get clusters
kubectl get machines
Lab 4: Deploy Karmada and Propagate Workloads
bash
# Install Karmada
helm repo add karmada https://raw.githubusercontent.com/karmada-io/karmada/master/charts
helm install karmada karmada/karmada -n karmada-system --create-namespace
# Join member clusters
karmadactl join member1 --cluster-kubeconfig=/path/to/member1
karmadactl join member2 --cluster-kubeconfig=/path/to/member2
# Create PropagationPolicy
cat <<'EOF' | kubectl apply -f -
apiVersion: policy.karmada.io/v1alpha1
kind: PropagationPolicy
metadata:
name: nginx-propagation
spec:
resourceSelectors:
- apiVersion: apps/v1
kind: Deployment
name: nginx
placement:
clusterAffinity:
clusterNames:
- member1
- member2
replicaScheduling:
replicaDivisionPreference: Weighted
replicaSchedulingType: Divided
weightPreference:
staticWeightList:
- targetCluster:
clusterNames:
- member1
weight: 1
- targetCluster:
clusterNames:
- member2
weight: 1
EOF
# Deploy workload
kubectl create deployment nginx --image=nginx --replicas=6
# Check propagation
kubectl get resourcebinding nginx-deployment -o yaml
Lab 5: Crossplane for Cloud Resources
bash
# Install Crossplane
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm install crossplane crossplane-stable/crossplane -n crossplane-system --create-namespace
# Install AWS provider
cat <<'EOF' | kubectl apply -f -
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: provider-aws
spec:
package: xpkg.upbound.io/upbound/provider-aws-s3:v1.0.0
EOF
# Create an S3 bucket
cat <<'EOF' | kubectl apply -f -
apiVersion: s3.aws.upbound.io/v1beta1
kind: Bucket
metadata:
name: my-crossplane-bucket
spec:
forProvider:
region: us-east-1
providerConfigRef:
name: default
EOF
# Check status
kubectl get bucket
kubectl describe bucket my-crossplane-bucket
Lab 6: Backstage Developer Portal
bash
# Create Backstage app
npx @backstage/create-app@latest
# Start Backstage
cd my-backstage-app
yarn dev
# Access at http://localhost:3000
# Add Kubernetes plugin
yarn add --cwd packages/app @backstage/plugin-kubernetes
Lab 7: Multi-Cluster GitOps with Argo CD
bash
# Install Argo CD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Add clusters
argocd cluster add production-context
argocd cluster add staging-context
# Create Application
cat <<'EOF' | kubectl apply -f -
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/myorg/myapp
targetRevision: HEAD
path: manifests
destination:
server: https://production.example.com:6443
namespace: default
syncPolicy:
automated:
prune: true
selfHeal: true
EOF
# Check status
argocd app list
argocd app get my-app
Lab 8: Multi-Cluster Observability
bash
# Install Thanos
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install thanos bitnami/thanos -n thanos --create-namespace
# Configure Prometheus remote write to Thanos
# In each cluster's Prometheus:
remote_write:
- url: http://thanos-receive:19291/api/v1/receive
# Query global view
# Access Thanos Query UI at http://thanos-query:9090
Lab 9: End-to-End Platform Engineering
bash
# This lab combines all components:
# 1. Management cluster with Cluster API
# 2. vCluster for developer environments
# 3. Capsule for tenant management
# 4. Crossplane for cloud resources
# 5. Backstage for portal
# 6. Argo CD for GitOps
# Step 1: Set up management cluster
kind create cluster --name management
# Step 2: Install Cluster API
clusterctl init --infrastructure docker
# Step 3: Provision workload clusters
clusterctl generate cluster dev --flavor development > dev.yaml
kubectl apply -f dev.yaml
# Step 4: Install vCluster on workload cluster
vcluster create dev-vcluster --namespace dev
# Step 5: Install Capsule
helm install capsule projectcapsule/capsule -n capsule-system --create-namespace
# Step 6: Install Crossplane
helm install crossplane crossplane-stable/crossplane -n crossplane-system --create-namespace
# Step 7: Install Argo CD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
# Step 8: Connect everything
# - Backstage to Argo CD
# - Argo CD to all clusters
# - Crossplane to cloud provider
# Verify
kubectl get all -A
1:1 copy of the class Google Doc, code in code blocks.