completed upto lab 38

This commit is contained in:
Mosiur Rahman
2026-08-27 14:03:17 +06:00
parent d74b79cfc6
commit ac6292db20
19 changed files with 220 additions and 204 deletions

View File

@@ -20,7 +20,15 @@ EOF
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get install -y ca-certificates curl gnupg jq vim git iproute2 iptables conntrack socat
apt-get install -y \
bash-completion ca-certificates conntrack curl dnsutils git gnupg iproute2 \
iptables iputils-ping jq less lsof man-db nano netcat-openbsd procps psmisc \
socat strace tcpdump tree vim wget yq
cat >/etc/profile.d/cks-lab.sh <<'EOF'
alias k=kubectl
complete -o default -F __start_kubectl k 2>/dev/null || true
EOF
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
@@ -45,20 +53,20 @@ curl -fsSLo "$tmp_dir/kubectl.sha256" "https://dl.k8s.io/release/${KUBECTL_VERSI
printf '%s %s\n' "$(cat "$tmp_dir/kubectl.sha256")" "$tmp_dir/kubectl" | sha256sum --check --status
install -m 0755 "$tmp_dir/kubectl" /usr/local/bin/kubectl
curl -fsSLo "$tmp_dir/kind" "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-amd64"
curl -fsSLo "$tmp_dir/kind-linux-amd64" "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-amd64"
curl -fsSLo "$tmp_dir/kind.sha256sum" "https://kind.sigs.k8s.io/dl/${KIND_VERSION}/kind-linux-amd64.sha256sum"
(cd "$tmp_dir" && sha256sum --check --status kind.sha256sum)
install -m 0755 "$tmp_dir/kind" /usr/local/bin/kind
install -m 0755 "$tmp_dir/kind-linux-amd64" /usr/local/bin/kind
curl -fsSLo "$tmp_dir/kube-bench.tar.gz" \
curl -fsSLo "$tmp_dir/kube-bench_${KUBE_BENCH_VERSION}_linux_amd64.tar.gz" \
"https://github.com/aquasecurity/kube-bench/releases/download/v${KUBE_BENCH_VERSION}/kube-bench_${KUBE_BENCH_VERSION}_linux_amd64.tar.gz"
curl -fsSLo "$tmp_dir/checksums.txt" \
"https://github.com/aquasecurity/kube-bench/releases/download/v${KUBE_BENCH_VERSION}/kube-bench_${KUBE_BENCH_VERSION}_checksums.txt"
(cd "$tmp_dir" && grep " kube-bench_${KUBE_BENCH_VERSION}_linux_amd64.tar.gz$" checksums.txt | sha256sum --check --status)
rm -rf /opt/cks-lab/tools/kube-bench
install -d /opt/cks-lab/tools/kube-bench
tar -xzf "$tmp_dir/kube-bench.tar.gz" -C /opt/cks-lab/tools/kube-bench
tar -xzf "$tmp_dir/kube-bench_${KUBE_BENCH_VERSION}_linux_amd64.tar.gz" -C /opt/cks-lab/tools/kube-bench
ln -sfn /opt/cks-lab/tools/kube-bench/kube-bench /usr/local/bin/kube-bench
printf 'Installed kubectl %s, Kind %s, and kube-bench %s.\n' \
printf 'Installed CKS command-line tools plus kubectl %s, Kind %s, and kube-bench %s.\n' \
"$KUBECTL_VERSION" "$KIND_VERSION" "$KUBE_BENCH_VERSION"

View File

@@ -31,9 +31,9 @@ if [[ "$context" != "kind-${CLUSTER_NAME}" ]]; then
exit 1
fi
kubectl apply -f "https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/operator-crds.yaml"
kubectl apply -f "https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/tigera-operator.yaml"
kubectl apply -f "https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/custom-resources.yaml"
kubectl apply --server-side --validate=false -f "https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/operator-crds.yaml"
kubectl apply --server-side --validate=false -f "https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/tigera-operator.yaml"
kubectl apply --server-side --validate=false -f "https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/custom-resources.yaml"
kubectl wait --for=condition=Available deployment/tigera-operator -n tigera-operator --timeout=300s
kubectl wait --for=condition=Ready nodes --all --timeout=600s
@@ -43,4 +43,3 @@ for node in "${CLUSTER_NAME}-control-plane" "${CLUSTER_NAME}-worker"; do
docker cp /opt/cks-lab/tools/kube-bench "$node":/opt/kube-bench
docker exec "$node" /opt/kube-bench/kube-bench version
done

View File

@@ -1,17 +1,9 @@
$ErrorActionPreference = 'Stop'
$distribution = 'Ubuntu-24.04'
$linuxScript = (& wsl.exe --distribution $distribution --user root --exec wslpath -a "$PSScriptRoot/enter-lab.sh").Trim()
if (-not $linuxScript) { throw 'Could not locate the Linux lab entry script.' }
& wsl.exe --distribution $distribution --user root --exec bash -lc @'
export KUBECONFIG=/opt/cks-lab/kubeconfig
context="$(kubectl config current-context 2>/dev/null || true)"
if [[ "$context" != "kind-cks-lab" ]]; then
echo "Safety check failed: expected kind-cks-lab, got ${context:-none}." >&2
exit 1
fi
echo "CKS lab: $(kubectl version --output=json | jq -r .serverVersion.gitVersion)"
echo "Context: $context"
exec bash
'@
& wsl.exe --distribution $distribution --user root --exec bash $linuxScript
if ($LASTEXITCODE -ne 0) { throw 'Could not enter the isolated CKS lab.' }

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -Eeuo pipefail
export KUBECONFIG=/opt/cks-lab/kubeconfig
expected_context=kind-cks-lab
context="$(kubectl config current-context 2>/dev/null || true)"
if [[ "$context" != "$expected_context" ]]; then
echo "Safety check failed: expected $expected_context, got ${context:-none}." >&2
exit 1
fi
echo "CKS lab: $(kubectl version --output=json | jq -r .serverVersion.gitVersion)"
echo "Context: $context"
required_tools=(kubectl kube-bench nano vim curl wget jq yq dig nc ss ps less)
missing_tools=()
for tool in "${required_tools[@]}"; do
command -v "$tool" >/dev/null 2>&1 || missing_tools+=("$tool")
done
if (( ${#missing_tools[@]} )); then
echo "Lab setup incomplete; missing: ${missing_tools[*]}. Run ./02-install-and-build.ps1." >&2
exit 1
fi
echo "Tools: ready (nano, curl, wget, jq, yq, dig, nc, tcpdump, ss); alias k=kubectl"
exec bash