Skip to content

Instantly share code, notes, and snippets.

@veggiemonk
Created May 16, 2023 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save veggiemonk/711c5010a3217a2f25f076164822dcfa to your computer and use it in GitHub Desktop.
Save veggiemonk/711c5010a3217a2f25f076164822dcfa to your computer and use it in GitHub Desktop.
starting a fake kubernetes cluster without docker or VMs

Testing kubernetes manifests without a cluster or cluster

The start.sh script is using kwok and Go.

To delete the cluster: kowkctl delete cluster --name fake

#!/usr/bin/env bash
set -exuo pipefail
command -v kwok > /dev/null || { echo "need to install kwok -> brew install kwok "; exit 1 ; }
TMP=~/tmp
KUBE_VERSION="v1.27.1"
function main {
mkdir -p "$TMP" && cd "$TMP"
wget https://dl.k8s.io/"$KUBE_VERSION"/kubernetes-src.tar.gz -O - | tar xz
#
# wget https://dl.k8s.io/"$KUBE_VERSION"/kubernetes-src.tar.gz && \
# tar xzf kubernetes-src.tar.gz
make WHAT=cmd/kube-apiserver
make WHAT=cmd/kube-controller-manager
make WHAT=cmd/kube-scheduler
KUBE_BIN="$TMP/_output/local/bin/$(go env GOOS)/$(go env GOARCH)"
kwokctl create cluster \
--name fake \
--runtime binary \
--kube-admission \
--kube-authorization \
--kubeconfig "$TMP"/kubeconfig \
--kube-controller-manager-binary "$KUBE_BIN"/kube-controller-manager \
--kube-apiserver-binary "$KUBE_BIN"/kube-apiserver \
--kube-scheduler-binary "$KUBE_BIN"/kube-scheduler
pushd "$TMP" > /dev/null
for i in $(seq 1 10);
do
export NODE="node-$i"
cat << EOH >> node.yaml
---
apiVersion: v1
kind: Node
metadata:
annotations:
kwok.x-k8s.io/node: fake
node.alpha.kubernetes.io/ttl: "0"
labels:
beta.kubernetes.io/arch: amd64
beta.kubernetes.io/os: linux
kubernetes.io/arch: arm64
kubernetes.io/hostname: ${NODE}
kubernetes.io/os: linux
kubernetes.io/role: agent
node-role.kubernetes.io/agent: ""
type: kwok-controller
name: ${NODE}
spec:
EOH
done
kubectl --context kwok-fake --kubeconfig "$TMP"/kubeconfig apply -f "$TMP"/node.yaml
echo
echo "To access the cluster:"
echo
echo " export KUBECONFIG=$TMP/kubeconfig"
echo
echo
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment