### Apply Ingress example configuration Source: https://kind.sigs.k8s.io/docs/user/ingress Applies the example configuration that creates foo and bar pods/services and an Ingress object to route to them. The configuration is fetched from the kind examples URL. ```bash kubectl apply -f https://kind.sigs.k8s.io/examples/ingress/usage.yaml ``` -------------------------------- ### Install kind with Winget on Windows Source: https://kind.sigs.k8s.io/docs/user/quick-start Installs kind via Winget. ```powershell winget install Kubernetes.kind ``` -------------------------------- ### Install Cloud Provider KIND with go install Source: https://kind.sigs.k8s.io/docs/user/loadbalancer Installs Cloud Provider KIND using the Go toolchain. Requires Go installed and privileges to open ports and connect to the container runtime. ```bash go install sigs.k8s.io/cloud-provider-kind@latest ``` -------------------------------- ### Check Go installation Source: https://kind.sigs.k8s.io/docs/contributing/getting-started Run this command to verify that Go is installed on your system. ```bash go version ``` -------------------------------- ### Install kind with Scoop on Windows Source: https://kind.sigs.k8s.io/docs/user/quick-start Adds the main bucket and installs kind via Scoop. ```powershell scoop bucket add main scoop install main/kind ``` -------------------------------- ### Install kind with Chocolatey on Windows Source: https://kind.sigs.k8s.io/docs/user/quick-start Installs kind via Chocolatey. ```powershell choco install kind ``` -------------------------------- ### Install kind on Linux from release binaries Source: https://kind.sigs.k8s.io/docs/user/quick-start Downloads the kind binary for AMD64 or ARM64, makes it executable, and moves it to /usr/local/bin. Requires curl and sudo. ```bash # For AMD64 / x86_64 [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.33.0/kind-linux-amd64 # For ARM64 [ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.33.0/kind-linux-arm64 chmod +x ./kind sudo mv ./kind /usr/local/bin/kind ``` -------------------------------- ### Check Docker installation Source: https://kind.sigs.k8s.io/docs/contributing/getting-started Run this command to verify that Docker is installed on your system. ```bash docker --version ``` -------------------------------- ### Check Git installation Source: https://kind.sigs.k8s.io/docs/contributing/getting-started Run this command to verify that Git is installed on your system. ```bash git --version ``` -------------------------------- ### Install kind with pacman on Arch Linux Source: https://kind.sigs.k8s.io/docs/user/quick-start Updates the package list and installs kind via pacman. ```bash sudo pacman -Syu kind ``` -------------------------------- ### Run kind with systemd-run for rootless Podman Source: https://kind.sigs.k8s.io/docs/user/rootless Starts kind in its own cgroup scope using systemd-run, which may be required on some distributions. ```bash $ systemd-run --scope --user kind create cluster ``` ```bash $ systemd-run --scope --user -p "Delegate=yes" kind create cluster ``` -------------------------------- ### Install kind with Homebrew on macOS Source: https://kind.sigs.k8s.io/docs/user/quick-start Installs kind via Homebrew on macOS. ```bash brew install kind ``` -------------------------------- ### Install kubectl via Homebrew Source: https://kind.sigs.k8s.io/docs/user/known-issues Install a newer kubectl client version using Homebrew on macOS. ```bash brew install kubernetes-cli ``` -------------------------------- ### Podman log driver error example Source: https://kind.sigs.k8s.io/docs/user/rootless Example error message when kind fails to create a cluster with rootless Podman due to log handling issues. ```bash ERROR: failed to create cluster: could not find a log line that matches "Reached target .*Multi-User System.*|detected cgroup v1" ``` -------------------------------- ### Install kind with MacPorts on macOS Source: https://kind.sigs.k8s.io/docs/user/quick-start Updates MacPorts and installs kind. ```bash sudo port selfupdate && sudo port install kind ``` -------------------------------- ### Check systemd version Source: https://kind.sigs.k8s.io/docs/user/rootless Run `systemctl --version` to check if systemd 252 or higher is installed, which enables cgroup delegation by default. Example output from a Fedora host shows systemd 257. ```bash $ systemctl --version systemd 257 (257.9-2.fc42) ``` -------------------------------- ### Failed to get rootfs info: kubelet error log Source: https://kind.sigs.k8s.io/docs/user/known-issues Example error messages from kubelet.log when creating a cluster times out due to missing device nodes. The device name varies (e.g., /dev/nvme0n1p3). ```log stat failed on /dev/nvme0n1p3 with error: no such file or directory "Failed to start ContainerManager" err="failed to get rootfs info: failed to get device for dir \"/var/lib/kubelet\": could not find device with major: 0, minor: 40 in cached partitions map" ``` -------------------------------- ### Build node image from source Source: https://kind.sigs.k8s.io/docs/user/working-offline Builds a KIND node image from Kubernetes source code using the kind build node-image command. The output shows the build starting and completing. ```bash ➜ ~ kind build node-image --image kindest/node:main $GOPATH/src/k8s.io/kubernetes Starting to build Kubernetes ... Image build completed. ``` -------------------------------- ### Structure of exported logs Source: https://kind.sigs.k8s.io/docs/user/quick-start Example directory tree showing the structure of exported logs, including docker-info.txt and a kind-control-plane directory with various log files. ```text . ├── docker-info.txt └── kind-control-plane/ ├── containers ├── docker.log ├── inspect.json ├── journal.log ├── kubelet.log ├── kubernetes-version.txt └── pods/ ``` -------------------------------- ### Select container runtime with KIND_EXPERIMENTAL_PROVIDER Source: https://kind.sigs.k8s.io/docs/user/quick-start Set the `KIND_EXPERIMENTAL_PROVIDER` environment variable to `docker`, `podman`, or `nerdctl` to select the container runtime instead of auto-detecting. Note that podman and nerdctl operate in rootless mode by default, requiring extra setup for kind clusters. ```bash KIND_EXPERIMENTAL_PROVIDER=docker ``` ```bash KIND_EXPERIMENTAL_PROVIDER=podman ``` ```bash KIND_EXPERIMENTAL_PROVIDER=nerdctl ``` -------------------------------- ### Check kubelet logs for eviction errors Source: https://kind.sigs.k8s.io/docs/user/known-issues Example log output from kubelet showing eviction manager messages indicating ephemeral-storage pressure, which can be found in exported logs. ```bash Dec 07 00:37:53 kind-1-control-plane kubelet[688]: I1207 00:37:53.229561 688 eviction_manager.go:340] eviction manager: must evict pod(s) to reclaim ephemeral-storage Dec 07 00:37:53 kind-1-control-plane kubelet[688]: E1207 00:37:53.229638 688 eviction_manager.go:351] eviction manager: eviction thresholds have been met, but no pods are active to evict ``` -------------------------------- ### Verify Ingress works - get Ingress and curl paths Source: https://kind.sigs.k8s.io/docs/user/ingress Checks the External IP assigned to the Ingress by the built-in LoadBalancer, then gets the Ingress IP and curls the /foo and /bar paths, which should output 'foo-app' and 'bar-app' respectively. ```bash kubectl get ingress NAME CLASS HOSTS ADDRESS PORTS AGE example-ingress example.com 172.18.0.5 80 10m ``` ```bash # get the Ingress IP INGRESS_IP=$(kubectl get ingress example-ingress -o jsonpath='{.status.loadBalancer.ingress[0].ip}') # should output "foo-app" curl ${INGRESS_IP}/foo # should output "bar-app" curl ${INGRESS_IP}/bar ``` -------------------------------- ### Build the base image with a custom TAG Source: https://kind.sigs.k8s.io/docs/contributing/development Set the `TAG` environment variable to change the base image tag. This example tags the image as `v0.1.0`. ```bash TAG=v0.1.0 make -C images/base quick ``` -------------------------------- ### sysctl config to lower unprivileged port start Source: https://kind.sigs.k8s.io/docs/user/rootless Create a .conf file in /etc/sysctl.d as root to set net.ipv4.ip_unprivileged_port_start=80, allowing unprivileged binding to port 80 (or 443 if needed). This is required to let KIND nodes bind to privileged ports. ```text # Allow unprivileged binding to HTTP port 80 # Use 443 if you only need binding to the default HTTPS port net.ipv4.ip_unprivileged_port_start=80 ``` -------------------------------- ### Create cluster with CLI name parameter Source: https://kind.sigs.k8s.io/docs/user/configuration Example CLI invocation showing that the `--name` parameter takes precedence over config file values. ```bash kind create cluster --name my-cluster ``` -------------------------------- ### Config with external credential store Source: https://kind.sigs.k8s.io/docs/user/private-registries Example Docker config.json that uses an external credential store (credsStore). This will not work when mounted because the credential helper binary is not present inside the node. ```json { "auths": {}, "credsStore": "desktop" } ``` -------------------------------- ### Config with plain credentials Source: https://kind.sigs.k8s.io/docs/user/private-registries Example Docker config.json containing plain base64 credentials in the auths field. This format works when mounted into a kind node. ```json { "auths": { "myregistry.example.com": { "auth": "dXNlcjpwYXNzd29yZA==" } } } ``` -------------------------------- ### Docker daemon.json default-address-pools configuration Source: https://kind.sigs.k8s.io/docs/user/known-issues Example configuration to add to daemon.json to avoid IPAM conflicts by using 10.253.0.0/16 as the default CIDR with /24 subnets. ```json "default-address-pools": [ { "base": "10.253.0.0/16", "size": 24 } ] ``` -------------------------------- ### Name Your Cluster with kind config Source: https://kind.sigs.k8s.io/docs/user/configuration Specify a custom name for your kind cluster using the 'name' field in the config. The example sets the cluster name to 'app-1-cluster'. ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 name: app-1-cluster ``` -------------------------------- ### Configure Runtime Config in kind Source: https://kind.sigs.k8s.io/docs/user/configuration Toggle Kubernetes API server runtime-config using the 'runtimeConfig' key, which maps to the '--runtime-config' kube-apiserver flag. The example disables the alpha API and enables the deprecated apps/v1beta2 API. ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 runtimeConfig: "api/alpha": "false" "apps/v1beta2": "true" ``` -------------------------------- ### kind Cluster config with extraMounts Source: https://kind.sigs.k8s.io/docs/user/configuration YAML configuration for a kind cluster that mounts host paths into the control-plane node. The example shows a basic mount and a second mount using all optional fields: readOnly, selinuxRelabel, and propagation. Note the warning that propagation is rarely needed and has limitations on macOS with Docker Desktop. ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane # add a mount from /path/to/my/files on the host to /files on the node extraMounts: - hostPath: /path/to/my/files containerPath: /files # # add an additional mount leveraging *all* of the config fields # # generally you only need the two fields above ... # - hostPath: /path/to/my/other-files/ containerPath: /other-files # optional: if set, the mount is read-only. # default false readOnly: true # optional: if set, the mount needs SELinux relabeling. # default false selinuxRelabel: false # optional: set propagation mode (None, HostToContainer or Bidirectional) # see https://kubernetes.io/docs/concepts/storage/volumes/#mount-propagation # default None # # WARNING: You very likely do not need this field. # # This field controls propagation of *additional* mounts created # *at runtime* underneath this mount. # # On MacOS with Docker Desktop, if the mount is from macOS and not the # docker desktop VM, you cannot use this field. You can use it for # mounts to the linux VM. propagation: None ``` -------------------------------- ### Error output when building node image fails due to memory Source: https://kind.sigs.k8s.io/docs/user/known-issues Example error output from `kind build node-image` when the build fails due to memory exhaustion. The output shows linker errors, call trees, and the final error message. This is used to identify the memory-related failure. ```text cmd/kube-scheduler cmd/kube-proxy /usr/local/go/pkg/tool/linux_amd64/link: signal: killed !!! [0116 08:30:53] Call tree: !!! [0116 08:30:53] 1: /go/src/k8s.io/kubernetes/hack/lib/golang.sh:614 kube::golang::build_some_binaries(...) !!! [0116 08:30:53] 2: /go/src/k8s.io/kubernetes/hack/lib/golang.sh:758 kube::golang::build_binaries_for_platform(...) !!! [0116 08:30:53] 3: hack/make-rules/build.sh:27 kube::golang::build_binaries(...) !!! [0116 08:30:53] Call tree: !!! [0116 08:30:53] 1: hack/make-rules/build.sh:27 kube::golang::build_binaries(...) !!! [0116 08:30:53] Call tree: !!! [0116 08:30:53] 1: hack/make-rules/build.sh:27 kube::golang::build_binaries(...) make: *** [all] Error 1 Makefile:92: recipe for target 'all' failed !!! [0116 08:30:54] Call tree: !!! [0116 08:30:54] 1: build/../build/common.sh:518 kube::build::run_build_command_ex(...) !!! [0116 08:30:54] 2: build/release-images.sh:38 kube::build::run_build_command(...) make: *** [quick-release-images] Error 1 ERRO[08:30:54] Failed to build Kubernetes: failed to build images: exit status 2 Error: error building node image: failed to build kubernetes: failed to build images: exit status 2 Usage: kind build node-image [flags] Flags: --base-image string name:tag of the base image to use for the build (default "kindest/base:v20181203-d055041") -h, --help help for node-image --image string name:tag of the resulting image to be built (default "kindest/node:latest") --type string build type, default is docker (default "docker") Global Flags: -q, --quiet silence all stderr output -v, --verbosity int32 info log verbosity, higher value produces more output error building node image: failed to build kubernetes: failed to build images: exit status 2 ``` -------------------------------- ### Failed to get rootfs info: KIND cluster config with extraMounts Source: https://kind.sigs.k8s.io/docs/user/known-issues Workaround for the rootfs info error by adding the necessary device as an extra mount in the KIND cluster configuration. The device path must match the one reported in the error. ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane extraMounts: - hostPath: /dev/nvme0n1p3 containerPath: /dev/nvme0n1p3 propagation: HostToContainer ``` -------------------------------- ### Enable Feature Gates in kind config Source: https://kind.sigs.k8s.io/docs/user/configuration Enable or disable Kubernetes feature gates cluster-wide using the 'featureGates' key. The example enables the 'CSIMigration' feature gate. ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 featureGates: # any feature gate can be enabled here with "Name": true # or disabled here with "Name": false # not all feature gates are tested, however "CSIMigration": true ``` -------------------------------- ### Pod with hostPort mapping Source: https://kind.sigs.k8s.io/docs/user/configuration Defines a Pod named 'foo' using the hashicorp/http-echo image, mapping container port 5678 to host port 80. This is an example of an HTTP pod that uses host ports. ```yaml kind: Pod apiVersion: v1 metadata: name: foo spec: containers: - name: foo image: hashicorp/http-echo:0.2.3 args: - "-text=foo" ports: - containerPort: 5678 hostPort: 80 ``` -------------------------------- ### Build, load, and apply a custom image workflow Source: https://kind.sigs.k8s.io/docs/user/quick-start Shows a workflow: build a Docker image, load it into the kind cluster, and apply a Kubernetes manifest that uses it. ```bash docker build -t my-custom-image:unique-tag ./my-image-dir kind load docker-image my-custom-image:unique-tag kubectl apply -f my-manifest-using-my-image.yaml ``` -------------------------------- ### Show help for kind create cluster Source: https://kind.sigs.k8s.io/docs/user/quick-start Displays usage details and available flags for the `kind create cluster` command. ```bash kind create cluster --help ``` -------------------------------- ### Create a kind cluster and local registry with shell script Source: https://kind.sigs.k8s.io/docs/user/local-registry Use this shell script to set up a local container registry and a kind cluster. It creates a Docker registry container named 'kind-registry' on port 5001, creates a kind cluster with containerd registry config, configures each node to use the registry, connects the registry to the cluster network, and applies a ConfigMap to document the local registry. Requires Docker and kind. The script uses 'set -o errexit' to stop on errors. ```shell #!/bin/sh # Copyright The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -o errexit # 1. Create registry container unless it already exists reg_name='kind-registry' reg_port='5001' if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then docker run \ -d --restart=always -p "127.0.0.1:${reg_port}:5000" --network bridge --name "${reg_name}" \ registry:3 fi # 2. Create kind cluster with containerd registry config dir enabled # # NOTE: the containerd config patch is not necessary with images from kind v0.27.0+ # It may enable some older images to work similarly. # If you're only supporting newer relases, you can just use `kind create cluster` here. # # See: # https://github.com/kubernetes-sigs/kind/issues/2875 # https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration # See: https://github.com/containerd/containerd/blob/main/docs/hosts.md cat <\ with the [wsl2] section pointing to the custom kernel bzImage path. ```ini [wsl2] kernel=c:\\path\\to\\your\\kernel\\bzImage ``` -------------------------------- ### Create delegate.conf for cgroup delegation Source: https://kind.sigs.k8s.io/docs/user/rootless Create the file `/etc/systemd/system/user@.service.d/delegate.conf` with the content shown to enable cgroup delegation for all controllers. ```ini [Service] Delegate=yes ``` -------------------------------- ### kubectl edit deploy error Source: https://kind.sigs.k8s.io/docs/user/known-issues Example error message when kubectl client is skewed from the kind node version, often occurring with Docker For Mac. ```bash $ kubectl edit deploy -n kube-system kubernetes-dashboard error: SchemaError(io.k8s.api.autoscaling.v2beta1.ExternalMetricStatus): invalid object doesn't have additional properties ``` -------------------------------- ### Discover kind command options with help Source: https://kind.sigs.k8s.io/docs/user/quick-start Use `kind help` or `kind --help` to explore available flags and usage details for kind commands and subcommands, such as `kind load image-archive`. ```bash kind help ``` ```bash kind --help ``` -------------------------------- ### Multi-node cluster config (two workers) Source: https://kind.sigs.k8s.io/docs/user/quick-start A kind Cluster configuration with one control-plane and two worker nodes. Use this as a starting point for multi-node clusters. ```yaml # three node (two workers) cluster config kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker - role: worker ``` -------------------------------- ### Download kind binary for Windows (PowerShell) Source: https://kind.sigs.k8s.io/docs/user/quick-start Downloads the kind v0.33.0 binary for Windows using curl.exe and moves it to a directory in your PATH. ```powershell curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.33.0/kind-windows-amd64 Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe ``` -------------------------------- ### Create kind cluster with Rootless Podman Source: https://kind.sigs.k8s.io/docs/user/rootless Sets the KIND_EXPERIMENTAL_PROVIDER environment variable to podman and creates a kind cluster. ```bash $ KIND_EXPERIMENTAL_PROVIDER=podman kind create cluster ``` -------------------------------- ### Add missing iptables modules Source: https://kind.sigs.k8s.io/docs/user/rootless Create `/etc/modules-load.d/iptables.conf` with the required kernel modules to load them at startup. ```bash sudo tee /etc/modules-load.d/iptables.conf > /dev/null <<'EOF' ip6_tables ip6table_nat ip_tables iptable_nat EOF ``` -------------------------------- ### Set node labels on multiple nodes with JoinConfiguration patches Source: https://kind.sigs.k8s.io/docs/user/configuration Configures node labels for multiple worker nodes and a control-plane node using separate JoinConfiguration patches. Each node gets its own label: 'my-label2=true' for workers and 'my-label3=true' for the control-plane. ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker - role: worker kubeadmConfigPatches: - | kind: JoinConfiguration nodeRegistration: kubeletExtraArgs: node-labels: "my-label2=true" - role: control-plane kubeadmConfigPatches: - | kind: JoinConfiguration nodeRegistration: kubeletExtraArgs: node-labels: "my-label3=true" ``` -------------------------------- ### Check API server mounts and arguments Source: https://kind.sigs.k8s.io/docs/user/auditing Greps the API server manifest for audit-related configuration to verify the mounts and arguments are present. ```bash docker exec kind-control-plane cat /etc/kubernetes/manifests/kube-apiserver.yaml | grep audit ``` -------------------------------- ### Build node image with explicit --type parameter Source: https://kind.sigs.k8s.io/docs/user/quick-start Shows how to specify the build type explicitly using `--type` with values `url`, `file`, `release`, and `source`. Note: `url`, `file`, and `release` modes are only available in kind v0.24 and above. ```bash kind build node-image --type url https://dl.k8s.io/v1.30.0/kubernetes-server-linux-arm64.tar.gz kind build node-image --type file $HOME/Downloads/kubernetes-server-linux-amd64.tar.gz kind build node-image --type release v1.30.0 kind build node-image --type source $HOME/go/src/k8s.io/kubernetes/ ``` -------------------------------- ### Create kind cluster, deployment, and service Source: https://kind.sigs.k8s.io/docs/user/using-wsl2 Commands to create a kind cluster using the config file, deploy an nginx deployment, create a NodePort service, and access it via localhost:30000. ```bash kind create cluster --config=cluster-config.yml ``` ```bash kubectl create deployment nginx --image=nginx --port=80 ``` ```bash kubectl create service nodeport nginx --tcp=80:80 --node-port=30000 ``` ```bash curl localhost:30000 ``` -------------------------------- ### Create cluster with pre-built image Source: https://kind.sigs.k8s.io/docs/user/working-offline Creates a KIND cluster using the pre-built node image by specifying the --image flag. The output shows the cluster creation progress and the kubectl context. ```bash ➜ ~ kind create cluster --image kindest/node:v1.17.0 Creating cluster "kind" ... ✓ Ensuring node image (kindest/node:v1.17.0) 🖼 ✓ Preparing nodes 📦 ✓ Writing configuration 📜 ✓ Starting control-plane 🕹️ ✓ Installing CNI 🔌 ✓ Installing StorageClass 💾 Set kubectl context to "kind-kind" You can now use your cluster with: kubectl cluster-info --context kind-kind Have a question, bug, or feature request? Let us know! https://kind.sigs.k8s.io/#community 🙂 ``` -------------------------------- ### Apply the LoadBalancer usage manifest Source: https://kind.sigs.k8s.io/docs/user/loadbalancer Applies the manifest from the URL to create the pods and service in the cluster. ```bash kubectl apply -f https://kind.sigs.k8s.io/examples/loadbalancer/usage.yaml ``` -------------------------------- ### Configure Podman to use k8s-file log driver Source: https://kind.sigs.k8s.io/docs/user/rootless Appends a configuration to ~/.config/containers/containers.conf to set the log_driver to k8s-file, which helps kind reliably tail logs. ```bash mkdir -p ~/.config/containers cat >> ~/.config/containers/containers.conf <"${DOCKER_CONFIG}/config.json" { "auths": { "gcr.io": {} } } EOF # login to gcr in DOCKER_CONFIG using an access token # https://cloud.google.com/container-registry/docs/advanced-authentication#access_token echo "Logging in to GCR in temporary docker client config directory ..." gcloud auth print-access-token | \ docker login -u oauth2accesstoken --password-stdin https://gcr.io # setup credentials on each node echo "Moving credentials to kind cluster name='${KIND_CLUSTER_NAME}' nodes ..." for node in $(kind get nodes --name "${KIND_CLUSTER_NAME}"); do # the -oname format is kind/name (so node/name) we just want name node_name=${node#node/} # copy the config to where kubelet will look docker cp "${DOCKER_CONFIG}/config.json" "${node_name}:/var/lib/kubelet/config.json" # restart kubelet to pick up the config docker exec "${node_name}" systemctl restart kubelet.service done echo "Done!" ``` -------------------------------- ### Export single-platform image and load archive Source: https://kind.sigs.k8s.io/docs/user/known-issues Workaround for kind load failures: export only the required platform and load the resulting archive. ```bash docker image save \ --platform linux/amd64 \ --output /tmp/image.tar \ my-image:tag kind load image-archive /tmp/image.tar --name my-cluster ``` -------------------------------- ### Build node image from a custom Kubernetes source path Source: https://kind.sigs.k8s.io/docs/user/quick-start Builds a kind node-image from a specified Kubernetes source directory. ```bash kind build node-image /path/to/kubernetes/source ``` -------------------------------- ### Create kind cluster with Rootless Docker Source: https://kind.sigs.k8s.io/docs/user/rootless Sets the DOCKER_HOST environment variable to the rootless Docker socket and creates a kind cluster. ```bash $ export DOCKER_HOST=unix://${XDG_RUNTIME_DIR}/docker.sock $ kind create cluster ``` -------------------------------- ### Create a kind cluster Source: https://kind.sigs.k8s.io/docs/user/ingress Creates a kind cluster. Ensure your host is properly configured if using a rootless container runtime, as most Ingress and Gateway controllers will not work otherwise. ```bash kind create cluster ``` -------------------------------- ### Build node image from a Kubernetes release version Source: https://kind.sigs.k8s.io/docs/user/quick-start Builds a kind node-image by specifying a Kubernetes release version directly, picking up official tar-gzipped files. ```bash kind build node-image v1.30.0 ``` -------------------------------- ### Create systemd user service directory Source: https://kind.sigs.k8s.io/docs/user/rootless Create the directory `/etc/systemd/system/user@.service.d/` if it is not present, required for the cgroup delegation configuration file. ```bash sudo mkdir -p /etc/systemd/system/user@.service.d/ ``` -------------------------------- ### Enable OOM watching by allowing dmesg Source: https://kind.sigs.k8s.io/docs/user/rootless Run this sysctl command to allow dmesg, which is needed to enable OOM watching. ```bash sysctl -w kernel.dmesg_restrict=0 ``` -------------------------------- ### Create a local registry and KIND cluster with containerd registry config Source: https://kind.sigs.k8s.io/docs/user/local-registry This shell script creates a local Docker registry container and a KIND cluster with containerd registry configuration enabled. It also adds the registry config to the nodes, connects the registry to the cluster network, and documents the local registry via a ConfigMap. The script is idempotent and uses the registry name 'kind-registry' and port '5001'. ```shell #!/bin/sh # Copyright The Kubernetes Authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. set -o errexit # 1. Create registry container unless it already exists reg_name='kind-registry' reg_port='5001' if [ "$(docker inspect -f '{{.State.Running}}' "${reg_name}" 2>/dev/null || true)" != 'true' ]; then docker run \ -d --restart=always -p "127.0.0.1:${reg_port}:5000" --network bridge --name "${reg_name}" \ registry:3 fi # 2. Create kind cluster with containerd registry config dir enabled # # NOTE: the containerd config patch is not necessary with images from kind v0.27.0+ # It may enable some older images to work similarly. # If you're only supporting newer relases, you can just use `kind create cluster` here. # # See: # https://github.com/kubernetes-sigs/kind/issues/2875 # https://github.com/containerd/containerd/blob/main/docs/cri/config.md#registry-configuration # See: https://github.com/containerd/containerd/blob/main/docs/hosts.md cat <"${DOCKER_CONFIG}/config.json" { "auths": { "myregistry.example.com": {} } } EOF # Log in — credentials will be written as plain base64 auth in the file docker login myregistry.example.com # Use ${DOCKER_CONFIG}/config.json as your hostPath ``` -------------------------------- ### Create kind-config.yaml Source: https://kind.sigs.k8s.io/docs/user/auditing Creates a kind configuration file that enables audit logging by passing kubeadmConfigPatches to the API server. It mounts the audit policy file and sets up log and policy volumes. ```yaml cat < kind-config.yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane kubeadmConfigPatches: - | kind: ClusterConfiguration apiServer: # enable auditing flags on the API server extraArgs: audit-log-path: /var/log/kubernetes/kube-apiserver-audit.log audit-policy-file: /etc/kubernetes/policies/audit-policy.yaml # mount new files / directories on the control plane extraVolumes: - name: audit-policies hostPath: /etc/kubernetes/policies mountPath: /etc/kubernetes/policies readOnly: true pathType: "DirectoryOrCreate" - name: "audit-logs" hostPath: "/var/log/kubernetes" mountPath: "/var/log/kubernetes" readOnly: false pathType: DirectoryOrCreate # mount the local file on the control plane extraMounts: - hostPath: ./audit-policy.yaml containerPath: /etc/kubernetes/policies/audit-policy.yaml readOnly: true EOF ``` -------------------------------- ### Authenticate Docker with Service Account Key Source: https://kind.sigs.k8s.io/docs/user/private-registries Uses the service account key file to authenticate Docker with a private registry. Replace with the path to your key file. ```bash cat | docker login -u _json_key --password-stdin https://gcr.io ``` -------------------------------- ### Check IPv6 support on Linux Source: https://kind.sigs.k8s.io/docs/user/configuration Run this command to verify that IPv6 is enabled on the host. A value of `0` for `net.ipv6.conf.all.disable_ipv6` indicates IPv6 is enabled. ```bash sudo sysctl net.ipv6.conf.all.disable_ipv6 ```