### Install kind using go install Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Install the kind binary using `go install`. Requires Go version 1.16 or greater. The binary is typically placed in the `bin` directory of your Go workspace. ```bash go install sigs.k8s.io/kind@{{< stableVersion >}} ``` -------------------------------- ### Install kind from local source clone Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Install kind from a local source clone using `go install .` from the top-level directory of the repository. ```bash go install . ``` -------------------------------- ### Install kind CLI Source: https://context7.com/kubernetes-sigs/kind/llms.txt Install the kind binary using Go, Homebrew, or direct download. Ensure you have Go 1.16+ for `go install`. After downloading, make the binary executable and move it to your PATH. ```bash # Install via go install (requires Go 1.16+) go install sigs.k8s.io/kind@v0.31.0 ``` ```bash # macOS via Homebrew brew install kind ``` ```bash # Linux — AMD64 curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.31.0/kind-linux-amd64 chmod +x ./kind && sudo mv ./kind /usr/local/bin/kind ``` ```bash # Linux — ARM64 curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.31.0/kind-linux-arm64 chmod +x ./kind && sudo mv ./kind /usr/local/bin/kind ``` ```powershell # Windows (PowerShell) curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.31.0/kind-windows-amd64 Move-Item .\kind-windows-amd64.exe c:\Windows\System32\kind.exe ``` ```bash # Verify kind version # kind v0.31.0 go1.23.4 linux/amd64 ``` -------------------------------- ### Install Cloud Provider KIND Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/loadbalancer.md Install the cloud-provider-kind binary using go. This tool is required to provision load balancer containers for services. ```bash go install sigs.k8s.io/cloud-provider-kind@latest ``` -------------------------------- ### Install Kind with Scoop on Windows Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Install kind on Windows using the Scoop package manager. This involves adding the main bucket and then installing kind. ```powershell scoop bucket add main scoop install main/kind ``` -------------------------------- ### Install kind with Go Source: https://github.com/kubernetes-sigs/kind/blob/main/README.md Install the latest version of kind using Go. Ensure you have Go 1.16+ and Docker installed. This command places 'kind' in your GOPATH/bin directory. ```bash go install sigs.k8s.io/kind@v0.31.0 ``` -------------------------------- ### Install kind on Linux Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Download and install the kind binary for Linux AMD64 or ARM64 architectures. Ensures the binary is executable and moves it to a system-wide PATH. ```bash # For AMD64 / x86_64 [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/{{< stableVersion >}}/kind-linux-amd64 # For ARM64 [ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/{{< stableVersion >}}/kind-linux-arm64 chmod +x ./kind sudo mv ./kind /usr/local/bin/kind ``` -------------------------------- ### Install kind on Linux Source: https://github.com/kubernetes-sigs/kind/blob/main/README.md Download and install the kind binary for Linux AMD64 or ARM64. This script checks your architecture, downloads the appropriate binary, makes it executable, and moves it to /usr/local/bin. ```bash # For AMD64 / x86_64 [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.31.0/kind-$(uname)-amd64 # For ARM64 [ $(uname -m) = aarch64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.31.0/kind-$(uname)-arm64 chmod +x ./kind sudo mv ./kind /usr/local/bin/kind ``` -------------------------------- ### Install kind on Windows Source: https://github.com/kubernetes-sigs/kind/blob/main/README.md Download and install the kind binary for Windows AMD64. This command downloads the executable and provides instructions for moving it to your PATH. Alternatively, Chocolatey can be used. ```powershell curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/v0.31.0/kind-windows-amd64 Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe # OR via Chocolatey (https://chocolatey.org/packages/kind) choco install kind ``` -------------------------------- ### Install Kind with Chocolatey on Windows Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Install kind on Windows using the Chocolatey package manager. ```powershell choco install kind ``` -------------------------------- ### Install kind in GitHub Actions Source: https://context7.com/kubernetes-sigs/kind/llms.txt Installs the kind binary on an Ubuntu runner. Ensure the version matches your requirements. ```yaml - name: Install kind run: | curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.31.0/kind-linux-amd64 chmod +x ./kind && sudo mv ./kind /usr/local/bin/kind ``` -------------------------------- ### Install Kind with Winget on Windows Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Install kind on Windows using the Winget package manager. This command installs the kind package from the Microsoft winget-pkgs repository. ```powershell winget install Kubernetes.kind ``` -------------------------------- ### Launch kind cluster with configuration Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/auditing.md Creates a new kind cluster using the specified configuration file, which includes audit logging setup. ```bash kind create cluster --config kind-config.yaml ``` -------------------------------- ### Install kind on Windows (PowerShell) Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Download the kind binary for Windows AMD64 using PowerShell and move it to a directory in your system's PATH. ```powershell curl.exe -Lo kind-windows-amd64.exe https://kind.sigs.k8s.io/dl/{{< stableVersion >}}/kind-windows-amd64 Move-Item .\kind-windows-amd64.exe c:\some-dir-in-your-PATH\kind.exe ``` -------------------------------- ### Install kind on macOS Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Download and install the kind binary for macOS on Intel or ARM (M1) Macs. Makes the binary executable and moves it to a directory in your PATH. ```bash # For Intel Macs [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/{{< stableVersion >}}/kind-darwin-amd64 # For M1 / ARM Macs [ $(uname -m) = arm64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/{{< stableVersion >}}/kind-darwin-arm64 chmod +x ./kind mv ./kind /some-dir-in-your-PATH/kind ``` -------------------------------- ### Check Git Installation Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/contributing/getting-started.md Verify if Git is installed and accessible on your system. ```bash git --version ``` -------------------------------- ### Build kind with Docker Source: https://github.com/kubernetes-sigs/kind/blob/main/README.md Build the kind binary reproducibly using Docker, without needing to install Go locally. This is an alternative to installing Go. ```bash make build ``` -------------------------------- ### Install kind on macOS via Bash Source: https://github.com/kubernetes-sigs/kind/blob/main/README.md Download and install the kind binary for macOS Intel or ARM Macs. This script checks your architecture, downloads the binary, makes it executable, and moves it to a directory in your PATH. ```bash # For Intel Macs [ $(uname -m) = x86_64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.31.0/kind-darwin-amd64 # For M1 / ARM Macs [ $(uname -m) = arm64 ] && curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.31.0/kind-darwin-arm64 chmod +x ./kind mv ./kind /some-dir-in-your-PATH/kind ``` -------------------------------- ### Install kind on macOS with MacPorts Source: https://github.com/kubernetes-sigs/kind/blob/main/README.md Install kind on macOS using the MacPorts package manager. Ensure MacPorts is up-to-date before installing. ```bash sudo port selfupdate && sudo port install kind ``` -------------------------------- ### Check Docker Installation Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/contributing/getting-started.md Verify if Docker is installed and accessible on your system. This is required for creating clusters. ```bash docker --version ``` -------------------------------- ### Apply LoadBalancer Service Example Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/loadbalancer.md Apply the example load balancer service definition to your kind cluster. This configuration routes traffic to http-echo pods. ```yaml apiVersion: v1 kind: Service metadata: name: foo-service spec: selector: app: foo ports: - protocol: TCP port: 5678 targetPort: 5678 type: LoadBalancer --- apiVersion: v1 kind: Service metadata: name: bar-service spec: selector: app: bar ports: - protocol: TCP port: 5678 targetPort: 5678 type: LoadBalancer ``` ```yaml kubectl apply -f https://kind.sigs.k8s.io/examples/loadbalancer/usage.yaml ``` -------------------------------- ### Example Log Structure Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Illustrates the typical file and directory structure of exported kind cluster logs. This helps in understanding the content of the logs. ```text . ├── docker-info.txt └── kind-control-plane/ ├── containers ├── docker.log ├── inspect.json ├── journal.log ├── kubelet.log ├── kubernetes-version.txt └── pods/ ``` -------------------------------- ### Install kind on macOS with Homebrew Source: https://github.com/kubernetes-sigs/kind/blob/main/README.md Install kind on macOS using the Homebrew package manager. This is a simple and recommended method for macOS users. ```bash brew install kind ``` -------------------------------- ### Apply Ingress Configuration Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/ingress.md Applies a Kubernetes Ingress configuration to the cluster. This example assumes a static file named 'usage.yaml' is available. ```yaml apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: example-ingress annotations: nginx.ingress.kubernetes.io/rewrite-target: / spec: rules: - host: example.com http: paths: - path: /foo pathType: Prefix backend: service: name: http-echo-service port: number: 80 - path: /bar pathType: Prefix backend: service: name: http-echo-service port: number: 80 --- apiVersion: v1 kind: Service metadata: name: http-echo-service spec: ports: - port: 80 targetPort: 80 selector: app: http-echo --- apiVersion: apps/v1 kind: Deployment metadata: name: http-echo-deployment spec: replicas: 1 selector: matchLabels: app: http-echo template: metadata: labels: app: http-echo spec: containers: - name: http-echo image: hashicorp/http-echo args: - "-text=foo-app" - "-listen=:80" --- apiVersion: apps/v1 kind: Deployment metadata: name: http-echo-deployment-bar spec: replicas: 1 selector: matchLabels: app: http-echo-bar template: metadata: labels: app: http-echo-bar spec: containers: - name: http-echo image: hashicorp/http-echo args: - "-text=bar-app" - "-listen=:80" --- apiVersion: v1 kind: Service metadata: name: http-echo-service-bar spec: ports: - port: 80 targetPort: 80 selector: app: http-echo-bar ``` ```bash kubectl apply -f $(kind get kubeconfig-path)/examples/ingress/usage.yaml ``` -------------------------------- ### Local Registry Integration with Kind Source: https://context7.com/kubernetes-sigs/kind/llms.txt This bash script demonstrates setting up a local Docker registry and configuring Kind to use it. This allows nodes to pull images without authentication or internet access. Ensure Docker is installed and running. ```bash # 1. Create a local registry container docker run -d --restart=always -p 5001:5000 --name registry registry:2 # 2. Connect the registry to the kind network after cluster creation kind create cluster --name registry-cluster --config - < --help` for detailed usage. ```bash kind help kind --help kind --help ``` -------------------------------- ### Create Cluster with Minimal Configuration Source: https://context7.com/kubernetes-sigs/kind/llms.txt Creates a kind cluster using a minimal configuration file. This setup defaults to one control-plane node and IPv4 networking. ```bash kind create cluster --config kind-single.yaml ``` -------------------------------- ### Run Unit Tests Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/contributing/development.md Invoke this command to run only the unit tests. It ensures the correct Go version is used without requiring manual tooling installation. ```bash make unit ``` -------------------------------- ### Generate GCR Credentials with Access Token Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/private-registries.md Example shell snippet for generating a gcr.io credential file on the host machine using Access Tokens. This requires restarting kubelet on each node to apply. ```shell #!/bin/bash # This script is an example and may need adjustments # For example, to use a different registry or authentication method. # Set your desired registry and image REGISTRY="gcr.io" IMAGE="your-private-image:latest" # Authenticate Docker to the registry using an access token # Replace with your actual access token generation method ACCESS_TOKEN=$(gcloud auth print-access-token) docker login -u "_json_key" --password-stdin "https://${REGISTRY}" < echo "Image ${REGISTRY}/${IMAGE} loaded into kind cluster." ``` -------------------------------- ### Create Cluster with Specific Name via CLI Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/configuration.md Example of creating a KIND cluster with a specific name using the command-line interface. CLI parameters take precedence over configuration file settings. ```bash kind create cluster --name my-cluster ``` -------------------------------- ### Mount Certificates for Certificate-Authenticated Registry Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/private-registries.md Mount host certificate and key files to the kind node for registries authenticated with certificates. This example also includes a containerd patch for older kind versions. ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane # This option mounts the host docker registry folder into # the control-plane node, allowing containerd to access them. extraMounts: - containerPath: /etc/docker/certs.d/registry.dev.example.com hostPath: /etc/docker/certs.d/registry.dev.example.com # NOTE: the following patch is not necessary with images from kind v0.27.0+ # It may enable some older images to work similarly containerdConfigPatches: - |- [plugins."io.containerd.grpc.v1.cri".registry] config_path = "/etc/containerd/certs.d" ``` -------------------------------- ### Configure Kind Cluster Networking Options Source: https://context7.com/kubernetes-sigs/kind/llms.txt Sets up networking for a kind cluster, including IP family (dual-stack), API server port, pod/service CIDRs, and kube-proxy mode. Disable the default CNI if installing a custom one. ```yaml # kind-networking.yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 networking: ipFamily: dual # ipv4 | ipv6 | dual apiServerPort: 6443 # 0 = random; -1 = let Docker pick apiServerAddress: "127.0.0.1" podSubnet: "10.244.0.0/16,fd00:10:244::/56" serviceSubnet: "10.96.0.0/16,fd00:10:96::/112" disableDefaultCNI: false # set true to install your own CNI kubeProxyMode: nftables # iptables | ipvs | nftables dnsSearch: [] # override host DNS search nodes: - role: control-plane - role: worker ``` ```bash kind create cluster --name dual-stack --config kind-networking.yaml ``` -------------------------------- ### Map Host Port to Container Port for HTTP Pod Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/configuration.md This example demonstrates mapping a host port (80) to a container port (5678) for a specific pod running a web server. ```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 ``` -------------------------------- ### Typical Image Loading Workflow Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md A common workflow demonstrating building a Docker image and then loading it into kind for use in Kubernetes. ```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 ``` -------------------------------- ### Serve Local Documentation Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/contributing/development.md Run a local instance of the documentation site using Hugo. This command is useful for previewing changes during development. ```bash make -C site serve ``` -------------------------------- ### Build Test Image with Make Source: https://github.com/kubernetes-sigs/kind/blob/main/images/local-path-helper/README.md Use this command to build a test image for the local-path-provisioner helper pod. ```bash make quick ``` -------------------------------- ### Push Image with Make Source: https://github.com/kubernetes-sigs/kind/blob/main/images/local-path-helper/README.md Use this command to push an actual image of the local-path-provisioner helper. ```bash make push ``` -------------------------------- ### cluster.NewProvider and Provider.Create Source: https://context7.com/kubernetes-sigs/kind/llms.txt Demonstrates initializing a cluster provider and creating a cluster using functional options, including configuration from a v1alpha4 struct, wait for ready, retain, and display options. ```APIDOC ## Go API — `cluster.NewProvider` and `Provider.Create` ### Description Initializes a cluster provider with optional logger and container runtime, then creates a Kubernetes cluster using functional options that mirror CLI flags. ### Method `cluster.NewProvider(options...cluster.ProviderOption)` `provider.Create(name string, options...cluster.CreateOption)` ### Parameters #### `cluster.NewProvider` Options - `cluster.ProviderWithLogger(logger)`: Sets the logger for the provider. - `cluster.ProviderWithDocker()`: Explicitly uses Docker as the container runtime. - `cluster.ProviderWithPodman()`: Explicitly uses Podman as the container runtime. - `cluster.ProviderWithNerdctl(path)`: Explicitly uses nerdctl as the container runtime. #### `provider.Create` Options - `cluster.CreateWithV1Alpha4Config(cfg *v1alpha4.Cluster)`: Creates the cluster using the provided v1alpha4 configuration struct. - `cluster.CreateWithWaitForReady(duration)`: Waits for the cluster to be ready for the specified duration. - `cluster.CreateWithRetain(bool)`: Retains the cluster on error if true. - `cluster.CreateWithDisplayUsage(bool)`: Displays usage information after creation. - `cluster.CreateWithDisplaySalutation(bool)`: Displays a salutation after creation. ### Example Usage ```go package main import ( "time" "fmt" "sigs.k8s.io/kind/pkg/cluster" "sigs.k8s.io/kind/pkg/cmd" "sigs.k8s.io/kind/pkg/apis/config/v1alpha4" ) func main() { logger := cmd.NewLogger() provider := cluster.NewProvider( cluster.ProviderWithLogger(logger), ) cfg := &v1alpha4.Cluster{ TypeMeta: v1alpha4.TypeMeta{ Kind: "Cluster", APIVersion: "kind.x-k8s.io/v1alpha4", }, Nodes: []v1alpha4.Node{ {Role: v1alpha4.ControlPlaneRole}, {Role: v1alpha4.WorkerRole}, }, Networking: v1alpha4.Networking{ IPFamily: v1alpha4.IPv4Family, }, } err := provider.Create( "my-cluster", cluster.CreateWithV1Alpha4Config(cfg), cluster.CreateWithWaitForReady(3*time.Minute), cluster.CreateWithRetain(false), cluster.CreateWithDisplayUsage(true), cluster.CreateWithDisplaySalutation(true), ) if err != nil { panic(fmt.Sprintf("failed to create cluster: %v", err)) } clusters, _ := provider.List() fmt.Println("clusters:", clusters) // [my-cluster] kubeconfig, _ := provider.KubeConfig("my-cluster", false) fmt.Println(kubeconfig) if err := provider.Delete("my-cluster", ""); err != nil { panic(err) } } ``` ``` -------------------------------- ### Disable Default CNI Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/configuration.md Disable the default CNI installation by setting `disableDefaultCNI` to `true` in the `networking` section. This is a power user feature for installing alternative CNIs. ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 networking: # the default CNI will not be installed disableDefaultCNI: true ``` -------------------------------- ### Provider.Create with Config File or Raw YAML Source: https://context7.com/kubernetes-sigs/kind/llms.txt Shows how to create a cluster by loading configuration from a file path or directly from raw YAML bytes. ```APIDOC ## Go API — `Provider.Create` with Config File or Raw YAML ### Description Load cluster configuration from a file on disk or from raw YAML bytes. ### Method `provider.Create(name string, options...cluster.CreateOption)` ### Parameters #### `provider.Create` Options - `cluster.CreateWithConfigFile(path string)`: Creates the cluster using configuration from the specified file path. - `cluster.CreateWithRawConfig(rawConfig []byte)`: Creates the cluster using the provided raw YAML configuration bytes. - `cluster.CreateWithNodeImage(image string)`: Specifies the node image to use for cluster creation. - `cluster.CreateWithWaitForReady(duration)`: Waits for the cluster to be ready for the specified duration. ### Example Usage ```go package main import ( "sigs.k8s.io/kind/pkg/cluster" "sigs.k8s.io/kind/pkg/cmd" "time" ) func main() { logger := cmd.NewLogger() provider := cluster.NewProvider(cluster.ProviderWithLogger(logger)) // Option A: from a config file path err := provider.Create("file-cluster", cluster.CreateWithConfigFile("/path/to/kind-config.yaml"), cluster.CreateWithWaitForReady(2*time.Minute), ) if err != nil { panic(err) } // Option B: from raw YAML bytes (e.g. embedded or generated at runtime) rawConfig := []byte(` kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane - role: worker `) err = provider.Create("raw-cluster", cluster.CreateWithRawConfig(rawConfig), cluster.CreateWithNodeImage("kindest/node:v1.30.0"), cluster.CreateWithWaitForReady(2*time.Minute), ) if err != nil { panic(err) } provider.Delete("file-cluster", "") provider.Delete("raw-cluster", "") } ``` ``` -------------------------------- ### Install Kubectl with Homebrew on Mac Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/known-issues.md If you are on macOS and experiencing kubectl version skew issues, you can install or update kubectl using Homebrew. This ensures you have a compatible client version. ```bash brew install kubernetes-cli ``` -------------------------------- ### Get Kubeconfig (Internal) Source: https://context7.com/kubernetes-sigs/kind/llms.txt Retrieves the kubeconfig for a kind cluster using its internal address, suitable for in-cluster access. ```bash # Use internal cluster address (for in-cluster access) kind get kubeconfig --name dev --internal ``` -------------------------------- ### Create Cluster with Configuration File Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Use the --config flag to specify a custom configuration file when creating a kind cluster. ```bash kind create cluster --config kind-example-config.yaml ``` -------------------------------- ### Programmatic cluster creation with kind API Source: https://context7.com/kubernetes-sigs/kind/llms.txt Demonstrates using the `sigs.k8s.io/kind/pkg/cluster` package to programmatically manage kind clusters. Uses functional options for configuration. ```go // Example of using the Provider API // For library integration, the sigs.k8s.io/kind/pkg/cluster package provides the full Provider API, // allowing tools like Cluster API, test frameworks, and custom CI scripts to programmatically manage kind cluster lifecycles. // The functional options pattern (CreateWithConfigFile, CreateWithV1Alpha4Config, CreateWithWaitForReady, etc.) // enables composable, type-safe configuration without breaking API changes. // The v1alpha4 config schema (YAML or Go struct) is the single source of truth for all cluster topology decisions and is stable across kind releases in the v0.x series. ``` -------------------------------- ### Create Kind Release Script Source: https://github.com/kubernetes-sigs/kind/blob/main/RELEASE.md Execute the create script to initiate the kind release process. Provide the current version and the next version as arguments. ```bash ./hack/release/create.sh ``` -------------------------------- ### Hugo codeFromInline Shortcode Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/contributing/development.md Creates a code block with a copy button from an inline code snippet. Use this for short, self-contained code examples. ```html {{}} func main() {{}} ``` -------------------------------- ### Run integration tests with kind Source: https://context7.com/kubernetes-sigs/kind/llms.txt Sets KUBECONFIG, applies Kubernetes manifests, waits for pods to be ready, and runs Go integration tests. Ensure your test files are correctly located. ```yaml - name: Run tests run: | export KUBECONFIG=$(kind get kubeconfig --name ci) kubectl apply -f ./k8s/ kubectl wait --for=condition=ready pod -l app=my-app --timeout=60s go test ./tests/integration/... -v ``` -------------------------------- ### Build node image and create cluster from source Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/_index.md Build a kind node image from Kubernetes source code and then create a cluster using that custom image. Ensure Kubernetes is cloned in the expected Go path. ```bash kind build node-image ``` ```bash kind create cluster --image kindest/node:latest ``` -------------------------------- ### Lint Shell Scripts Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/contributing/development.md Run this command to lint shell scripts using shellcheck. The linter is invoked via Docker, so no local installation is required. ```bash make shellcheck ``` -------------------------------- ### Create audit-policy.yaml Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/auditing.md Defines the level of granularity for Kubernetes API server audit logs. This example logs all requests at the "Metadata" level. ```bash cat < audit-policy.yaml apiVersion: audit.k8s.io/v1 kind: Policy rules: - level: Metadata EOF ``` -------------------------------- ### Create, List, and Delete Kind Clusters with Go API Source: https://context7.com/kubernetes-sigs/kind/llms.txt Demonstrates the full cluster lifecycle using the kind Go API. It shows how to create a cluster from a v1alpha4 config struct, list clusters, retrieve kubeconfig, and delete a cluster. Ensure necessary imports are present. ```go package main import ( "time" "fmt" "sigs.k8s.io/kind/pkg/cluster" "sigs.k8s.io/kind/pkg/cmd" "sigs.k8s.io/kind/pkg/apis/config/v1alpha4" ) func main() { logger := cmd.NewLogger() // Auto-detect Docker/Podman/nerdctl; falls back to Docker provider := cluster.NewProvider( cluster.ProviderWithLogger(logger), // cluster.ProviderWithDocker(), // explicit Docker // cluster.ProviderWithPodman(), // explicit Podman // cluster.ProviderWithNerdctl(""), // explicit nerdctl ) // Create from a v1alpha4 config struct cfg := &v1alpha4.Cluster{ TypeMeta: v1alpha4.TypeMeta{ Kind: "Cluster", APIVersion: "kind.x-k8s.io/v1alpha4", }, Nodes: []v1alpha4.Node{ {Role: v1alpha4.ControlPlaneRole}, {Role: v1alpha4.WorkerRole}, }, Networking: v1alpha4.Networking{ IPFamily: v1alpha4.IPv4Family, }, } err := provider.Create( "my-cluster", cluster.CreateWithV1Alpha4Config(cfg), cluster.CreateWithWaitForReady(3*time.Minute), cluster.CreateWithRetain(false), cluster.CreateWithDisplayUsage(true), cluster.CreateWithDisplaySalutation(true), ) if err != nil { panic(fmt.Sprintf("failed to create cluster: %v", err)) } // List clusters clusters, _ := provider.List() fmt.Println("clusters:", clusters) // [my-cluster] // Get kubeconfig (external address) kubeconfig, _ := provider.KubeConfig("my-cluster", false) fmt.Println(kubeconfig) // Delete cluster if err := provider.Delete("my-cluster", ""); err != nil { panic(err) } } ``` -------------------------------- ### Get Image Digest with Crane Source: https://github.com/kubernetes-sigs/kind/blob/main/RELEASE.md Retrieves the digest of a container image using the 'crane' tool. Useful for verifying image integrity or obtaining digests for configuration. ```bash crane digest gcr.io/k8s-staging-kind/node:v1.35.0 ``` -------------------------------- ### Run All Tests Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/contributing/development.md Execute this command to run all unit and integration tests for the project. This target automatically manages the correct Go version. ```bash make test ``` -------------------------------- ### Set WSL2 as Default Version in PowerShell Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/using-wsl2.md After rebooting, execute this command in an administrator PowerShell window to ensure that newly installed Linux distributions default to using WSL2. ```powershell wsl --set-default-version 2 ``` -------------------------------- ### Get Promoted Image Digest Source: https://github.com/kubernetes-sigs/kind/blob/main/RELEASE.md Retrieves the digest of a container image that has been promoted to Docker Hub. This digest is used to update the default image reference in the kind release. ```bash crane digest kindest/node:v1.35.0 ``` -------------------------------- ### Configure Dual Stack Networking Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/configuration.md Enable dual-stack networking for KIND clusters starting from version 0.11+ and Kubernetes versions 1.20+. This allows for both IPv4 and IPv6 communication. ```yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 networking: ipFamily: dual ``` -------------------------------- ### Link Kubectl with Homebrew on Mac Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/known-issues.md After installing or updating kubectl via Homebrew on macOS, use this command to overwrite existing symlinks, ensuring your system uses the Homebrew-managed kubectl. ```bash brew link --overwrite kubernetes-cli ``` -------------------------------- ### Lint Go Sources Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/contributing/development.md Execute this command to lint the Go source files using golangci-lint with a custom configuration. This is part of the `make verify` process. ```bash make lint ``` -------------------------------- ### Build and Push Node Image to Staging Source: https://github.com/kubernetes-sigs/kind/blob/main/RELEASE.md Build and push node images to a staging repository using the provided script. Replace 'vX.Y.Z' with the actual version. ```bash ./hack/release/push-node.sh vX.Y.Z ``` -------------------------------- ### Kubectl Cluster Info Connection Error Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/known-issues.md This error message from 'kubectl cluster-info' signifies that the client is unable to connect to the Kubernetes API server. This often occurs when the cluster has not started correctly. ```txt $ kind export kubeconfig $ kubectl cluster-info To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. Unable to connect to the server: EOF ``` -------------------------------- ### Build Kind Node Image from Source Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/working-offline.md Build a Kind node image from the cloned Kubernetes source code. This command requires the path to the Kubernetes source directory. ```bash ➜ ~ kind build node-image --image kindest/node:main $GOPATH/src/k8s.io/kubernetes ``` -------------------------------- ### Build Kind Node Image from URL or File Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/quick-start.md Builds a kind node image by specifying the Kubernetes tar-gzipped files from a URL or a local file path. ```bash kind build node-image https://dl.k8s.io/v1.30.0/kubernetes-server-linux-arm64.tar.gz ``` ```bash kind build node-image $HOME/Downloads/kubernetes-server-linux-amd64.tar.gz ``` -------------------------------- ### Create kind Cluster with Rootless nerdctl Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/rootless.md Create a kind cluster using nerdctl as the container runtime. Requires containerd v1.7 or later. ```console KIND_EXPERIMENTAL_PROVIDER=nerdctl kind create cluster ``` -------------------------------- ### Create a kind cluster with a configuration Source: https://context7.com/kubernetes-sigs/kind/llms.txt Creates a kind cluster using a multi-line YAML configuration. The --wait flag ensures the cluster is ready before proceeding. ```yaml - name: Create cluster run: | kind create cluster --name ci --wait 5m --config - <> ~/.config/containers/containers.conf < 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 ``` -------------------------------- ### Create Kind Release Source: https://github.com/kubernetes-sigs/kind/blob/main/RELEASE.md Automates the creation of a new kind release. It updates version information, creates Git tags, builds release binaries, and prepares for the next pre-release. ```bash ./hack/release/create.sh 0.31.0 0.32.0 ``` -------------------------------- ### Configure WSL2 Kernel in .wslconfig Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/using-wsl2.md Specify the path to your custom-built kernel image in the `.wslconfig` file located in your user profile directory. This tells WSL2 to use the new kernel, enabling features like session affinity. ```toml [wsl2] kernel=c:\path\to\your\kernel\bzImage ``` -------------------------------- ### Configure Kind Cluster Port Mappings and Host Mounts Source: https://context7.com/kubernetes-sigs/kind/llms.txt Exposes container ports on the host and mounts host paths into kind nodes. Useful for accessing services or providing persistent storage. ```yaml # kind-ports-mounts.yaml kind: Cluster apiVersion: kind.x-k8s.io/v1alpha4 nodes: - role: control-plane extraPortMappings: - hostPort: 80 # host port containerPort: 80 # node container port listenAddress: "0.0.0.0" protocol: TCP # TCP | UDP | SCTP - hostPort: 443 containerPort: 443 extraMounts: - hostPath: /host/data containerPath: /data readOnly: false selinuxRelabel: false propagation: None # None | HostToContainer | Bidirectional - role: worker extraMounts: - hostPath: ./foo containerPath: /bar ``` ```bash kind create cluster --config kind-ports-mounts.yaml # Access services via localhost:80 / localhost:443 ``` -------------------------------- ### Detect Node Provider with Go API Source: https://context7.com/kubernetes-sigs/kind/llms.txt Detects the available container runtime (Docker, Podman, nerdctl) without fallback, allowing explicit handling of missing runtimes. Requires importing `sigs.k8s.io/kind/pkg/cluster` and `sigs.k8s.io/kind/pkg/cmd`. ```go package main import ( "fmt" "sigs.k8s.io/kind/pkg/cluster" "sigs.k8s.io/kind/pkg/cmd" ) func main() { logger := cmd.NewLogger() providerOpt, err := cluster.DetectNodeProvider() if err != nil { // No supported runtime (Docker/Podman/nerdctl) found fmt.Printf("no node provider available: %v\n", err) return } provider := cluster.NewProvider( cluster.ProviderWithLogger(logger), providerOpt, // Docker, Podman, or nerdctl — whichever was detected ) clusters, _ := provider.List() fmt.Println("existing clusters:", clusters) } ``` -------------------------------- ### Check Kubectl Version Source: https://github.com/kubernetes-sigs/kind/blob/main/site/content/docs/user/known-issues.md Use this command to verify the version of your kubectl client and the kind cluster's API server. Mismatched versions can lead to interaction problems. ```bash kubectl version ``` -------------------------------- ### Promote Image to Docker Hub Source: https://github.com/kubernetes-sigs/kind/blob/main/RELEASE.md Copies a container image from a staging registry to a public registry like Docker Hub using 'crane cp'. Requires the source image digest and the destination tag. ```bash crane cp \ gcr.io/k8s-staging-kind/node:v1.35.0@sha256: \ kindest/node:v1.35.0 ```