متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 138Kubernetes · Lab

How to create a local cluster with kind

You want to test a Helm chart, a NetworkPolicy, an upgrade or a CI pipeline — without touching a shared cluster. kind (Kubernetes in Docker) creates a real Kubernetes cluster as Docker containers in under a minute, with several nodes if you want, and deletes it just as fast. It is also the standard way to run Kubernetes tests in CI. This how-to creates a multi-node cluster, loads local images, exposes a port, and cleans up.

  • 5 الدروس
  • 4 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

138.1

The quick answer

kind create cluster --name lab
kubectl cluster-info --context kind-lab
kubectl get nodes
kind delete cluster --name lab

kind needs Docker (or Podman) and kubectl. Install kind as a single binary (see the full guide).

138.2

Step by step

  1. A multi-node cluster with a port to the host — a config file:
kind-lab.yaml
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
    extraPortMappings:
      - containerPort: 30080
        hostPort: 8080
  - role: worker
  - role: worker
kind create cluster --name lab --config kind-lab.yaml
kubectl get nodes
NAME                STATUS   ROLES           AGE   VERSION
lab-control-plane   Ready    control-plane   45s   v1.33.1
lab-worker          Ready    <none>          25s   v1.33.1
lab-worker2         Ready    <none>          25s   v1.33.1
  1. A specific Kubernetes version (to test an upgrade or match production): --image kindest/node:vX.Y.Z (use an image listed in the kind release notes).
  2. Use local images without a registry:
docker build -t shop/api:dev .
kind load docker-image shop/api:dev --name lab

In the Pod spec use image: shop/api:dev with imagePullPolicy: IfNotPresent.

  1. Reach an app — a NodePort on 30080 is mapped to localhost:8080 (config above), or simply port-forward:
kubectl port-forward svc/api 8000:80
  1. NetworkPolicies? kind's default CNI (kindnet) supports basic NetworkPolicies in newer versions; to test Calico/Cilium features, create the cluster with disableDefaultCNI: true and install that CNI.
  2. In CI — create a cluster per job, run tests, delete it (GitHub Actions has a ready helm/kind-action).
  3. Clean up:
kind get clusters
kind delete cluster --name lab

138.3

Check that it worked

kubectl get nodes shows all nodes Ready, a test Deployment starts, and kind delete cluster removes everything (no leftover containers in docker ps).

138.4

Common problems

ProblemCauseFix
Cannot connect to the Docker daemonDocker not running / no rights.Start Docker; your user in the docker group (or use rootless Podman with KIND_EXPERIMENTAL_PROVIDER=podman).
ErrImagePull for a local imageImage not loaded into kind, or imagePullPolicy: Always.kind load docker-image; IfNotPresent.
Too many open files / nodes not Readyinotify limits on the host.Raise fs.inotify.max_user_watches and max_user_instances.
Port on localhost does not answerNo extraPortMappings, or the Service is not on that NodePort.Map the port at create time; or use port-forward.
kubectl talks to the wrong clusterContext changed to kind-lab.kubectl config use-context NAME.
Cluster gone after a rebootContainers did not restart.Recreate it — kind clusters are throw-away.

138.5

Go further

1How do you use an image you built locally in a kind cluster?

kind load docker-image IMAGE --name CLUSTER and imagePullPolicy: IfNotPresent.

2Why is kind popular in CI pipelines?

A real cluster starts in about a minute and is deleted after the test — every job gets a clean cluster.

كل الأوامر في هذا الفصل