Environment Setup and Basic Operations

Create a local Kubernetes cluster with kind and kubectl, inspect nodes, create a Namespace using YAML, and check resource status.

🎯 Introduction

The previous article introduced Kubernetes clusters, nodes, and Pods. To learn Kubernetes hands-on, you also need a cluster where you can run commands.

You do not need to buy a server to get started. In this article, you will use kind to create a local cluster and kubectl to manage it. We will install the tools, create the cluster, inspect nodes, write YAML, and verify resources.

By the end, you should be able to create a local practice cluster independently and determine whether your commands succeeded. In the next article, you will use it to deploy a Node.js service.

This article includes simulated terminal output after the main commands so you can follow along even without running them. These examples were not generated on your computer: versions, addresses, timing, and some system Pod names may differ. Focus on the key fields and signs of success.

🧱 Understanding kind and kubectl

The two tools serve different purposes:

ToolPurposeUse in this article
kindCreates a local Kubernetes practice clusterCreates a cluster named node-course
kubectlSends management commands to a Kubernetes clusterInspects nodes and creates and queries resources

The name kind comes from Kubernetes IN Docker. This article uses Docker as the container runtime environment: kind creates Docker containers that act as Kubernetes nodes.

For now, think of the workflow as follows:

courseComponents.mermaid.loading

This diagram shows how the tools work together, rather than a precise network topology. Once the cluster exists, you mainly use kubectl to inspect and configure resources. Use kind when you need to create or delete the entire practice cluster.


🛠 Installing the tools

The example below uses macOS + Docker Desktop + Homebrew. Links for Windows and Linux are provided at the end of this section; the Kubernetes commands that follow are largely the same.

1. Prepare Docker

Install and start Docker Desktop. If you already installed Docker in an earlier course, you can use that environment.

Open a terminal and run:

docker info

This command displays Docker client and server information. The full output is usually long, so only the key sections are shown here:

Client:
 Version:    28.0.0
 Context:    desktop-linux

Server:
 Containers: 1
  Running: 0
 Server Version: 28.0.0

This is simulated output; you do not need this exact version. What matters is that the Server section appears without connection errors, confirming that the terminal can connect to the Docker engine.

If you see an error such as Cannot connect to the Docker daemon, check that Docker Desktop is running. Complete this check before creating the cluster.

2. Install kind and kubectl

If Homebrew is installed, run:

brew install kind
brew install kubernetes-cli

Homebrew prints download and installation logs, which may end like this:

==> Installing kind
🍺  /opt/homebrew/Cellar/kind/0.xx.x: ...
==> Installing kubernetes-cli
🍺  /opt/homebrew/Cellar/kubernetes-cli/1.xx.x: ...

This simulated output omits intermediate steps. Installation paths, versions, and logs vary between machines.

After installation, verify that both commands are available:

kind version
kubectl version --client

Simulated output:

$ kind version
kind v0.xx.x go1.xx.x darwin/arm64

$ kubectl version --client
Client Version: v1.xx.x
Kustomize Version: v5.x.x

If both commands display a version successfully, they are installed and runnable. The versions and system architecture shown are illustrative and do not need to match yours.

If you see brew: command not found, Homebrew is not available yet. Follow the instructions on the Homebrew website to install it, then return to these commands.

For other operating systems, use the official installation guides:


🚀 Creating and checking the local cluster

1. Create the cluster

Run in a terminal:

kind create cluster --name node-course --wait 60s

The command has three parts:

  • create cluster: Creates a Kubernetes cluster.
  • --name node-course: Names the cluster node-course.
  • --wait 60s: Waits up to 60 seconds for the control plane to become ready. If it times out, inspect the actual cluster state.

On the first run, kind may need to download the node image. The time required depends on your network and computer. Simulated output follows; the logs may vary slightly:

Creating cluster "node-course" ...
 ✓ Ensuring node image
 ✓ Preparing nodes
 ✓ Writing configuration
 ✓ Starting control-plane
 ✓ Installing CNI
 ✓ Installing StorageClass
 ✓ Waiting for control-plane ready
Set kubectl context to "kind-node-course"
You can now use your cluster with:

kubectl cluster-info --context kind-node-course

This output indicates that kind created the node, prepared the cluster components, and switched kubectl's current connection target to the new cluster. If the command reports an error or timeout, resolve it first. The simulated output above does not confirm that your own command succeeded.

After the command succeeds, confirm that the cluster exists:

kind get clusters

Simulated output:

$ kind get clusters
node-course

Seeing node-course means it appears in kind's cluster list. You still need to check the node status to confirm readiness.

2. See where the cluster runs

In the Docker environment used here, kind nodes are Docker containers. Run:

docker ps

Simulated output, with some columns and unrelated containers omitted for readability:

$ docker ps
CONTAINER ID   IMAGE                 STATUS         NAMES
8a3f2c1d9e00   kindest/node:v1.xx.x   Up 2 minutes   node-course-control-plane

Look at the final NAMES column: node-course-control-plane is the node container created by kind. The container ID, image version, and uptime vary by environment.

This container acts as a Kubernetes node in the local cluster. With its default configuration, kind normally creates one node that runs both the control plane and workloads.

The structure looks like this:

courseComponents.mermaid.loading

For clarity, the diagram separates control plane components from system Pods. In practice, some control plane components also run as static Pods. A kind node container is not an application Pod.

3. Check the current cluster connection

kubectl config current-context

Simulated output:

$ kubectl config current-context
kind-node-course

If the output is kind-node-course, kubectl currently targets the practice cluster you just created.

For now, think of a context as the cluster kubectl currently targets together with its associated access configuration.

You may eventually have multiple Kubernetes clusters on your computer, so check the current context before running commands.

Next, inspect the cluster connection information:

kubectl cluster-info

Simulated output; addresses and ports vary by environment:

$ kubectl cluster-info
Kubernetes control plane is running at https://127.0.0.1:51234
CoreDNS is running at https://127.0.0.1:51234/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

Kubernetes control plane is running at ... means kubectl can access the cluster's control plane. Here, 127.0.0.1 is a local address, not a public server you need to visit.

4. Inspect nodes

kubectl get nodes

The output may look like this:

NAME                        STATUS   ROLES           AGE   VERSION
node-course-control-plane   Ready    control-plane   2m    v1.x.y

This is simulated output; actual ages and versions may differ. A Ready status means the node is ready. The example's v1.x.y is a placeholder, not a real version number.

FieldMeaning
NAMENode name
STATUSNode status; Ready means it is ready
ROLESNode roles
AGETime since the node was created
VERSIONKubernetes version on the node

Once the node is Ready, you have completed the main goal of this article: your local Kubernetes cluster exists and is usable.

If creation fails, check that docker info works. If the node is not yet Ready, inspect errors from the creation command and check the node status again before continuing.


🧩 Creating your first resource with YAML

With the cluster ready, start with something smaller than deploying a Node.js service: create a Namespace.

For now, think of a Namespace as a grouping of resources within a Kubernetes cluster. For example, we can place course resources in a Namespace named course to keep them easy to identify.

1. Write the YAML

Create namespace.yaml with the following contents:

apiVersion: v1
kind: Namespace
metadata:
  name: course

Kubernetes commonly uses YAML files to describe resources you want to create or manage. This example introduces three fields:

FieldMeaningValue here
apiVersionAPI version for the resourcev1
kindResource typeNamespace
metadata.nameResource namecourse

Notice that name is indented beneath metadata, indicating that it belongs to metadata. This example uses two spaces; correct nesting matters, rather than requiring exactly two spaces.

2. Apply the resource configuration

Open a terminal in the directory containing namespace.yaml and run:

kubectl apply -f namespace.yaml

The -f flag reads the configuration from the specified file.

On successful initial creation, you will usually see:

namespace/course created

This means the Namespace named course was created. If you run the same command again without changing the file, the simulated output becomes:

namespace/course unchanged

unchanged means the configuration has not changed; it does not indicate a failure.

3. Check the result

Run:

kubectl get namespaces

The output may look like this:

NAME              STATUS   AGE
default           Active   5m
kube-system       Active   5m
course            Active   30s

Only some possible rows are shown here. Your list may contain other Namespaces.

NAME is the name, STATUS is the status, and AGE is the time since creation. If course appears with the status Active, the operation succeeded.

To inspect only course, run:

kubectl get namespace course

Simulated output:

$ kubectl get namespace course
NAME     STATUS   AGE
course   Active   1m

This avoids searching through every Namespace. The key check is that its status is Active.


🔎 Common inspection commands

When deploying the Node.js service later, you will frequently inspect Kubernetes resources. For now, learn these two basic commands.

1. Inspect resources with get

kubectl get nodes
kubectl get namespaces
kubectl get pods -A

get lists resources of a specified type and their basic status. Output for the first two commands was shown earlier.

Simulated output for the third command, showing only some system Pods:

$ kubectl get pods -A
NAMESPACE            NAME                                      READY   STATUS    RESTARTS   AGE
kube-system          coredns-xxxxxxxxxx-xxxxx                  1/1     Running   0          4m
kube-system          etcd-node-course-control-plane            1/1     Running   0          4m
kube-system          kube-apiserver-node-course-control-plane  1/1     Running   0          4m
local-path-storage   local-path-provisioner-xxxxxxxxxx-xxxxx   1/1     Running   0          4m

pods refers to Pod resources, and -A includes all Namespaces. READY shows the number of ready containers, STATUS shows Pod status, such as Running, and AGE shows how long the Pod has existed. Pod name suffixes and counts vary.

You have not deployed your order service yet, so most Pods shown are Kubernetes system components. This is expected.

2. Inspect details with describe

kubectl describe namespace course

Simulated output; fields may differ between versions:

$ kubectl describe namespace course
Name:         course
Labels:       kubernetes.io/metadata.name=course
Annotations:  <none>
Status:       Active

No resource quota.

No LimitRange resource.

Name is the resource name, Labels provides identifying metadata, and Status: Active means the Namespace is active. No resource quota means no resource quota is configured here.

describe displays more detailed resource information. Namespace output is fairly simple; this command becomes more useful when troubleshooting Pods later.

Keep this distinction in mind:

CommandBest used for
kubectl getQuickly listing resources and checking their current status
kubectl describeInspecting a resource in more detail

You do not need to memorize every kubectl command now. We will reuse these commands when deploying the service in the next article.


🧹 Cleaning up the practice environment

Keep the cluster if you plan to continue to the next article. It also uses the node-course cluster.

Once you have finished the course exercises and no longer need their resources, run:

kind delete cluster --name node-course

Simulated output:

$ kind delete cluster --name node-course
Deleting cluster "node-course" ...
Deleted nodes: [node-course-control-plane]

This command deletes the kind cluster and its practice resources; it does more than close the terminal. Do not run it if you intend to continue learning with this cluster.

If you are just taking a break, you can shut down your computer or Docker Desktop; you do not need to delete the cluster. Before your next session, start Docker Desktop and check node status. If the existing cluster does not recover normally, investigate its actual state.


❓ Questions and answers

Q: Why does the cluster have only one node?

kind creates a single-node cluster by default. This is enough for the initial Kubernetes exercises. Create a multi-node cluster later when you need to learn about multiple nodes.

Q: Are kind, Docker, and kubectl the same thing?

No. Docker provides the container environment, kind uses containers to create a local Kubernetes cluster, and kubectl manages the Kubernetes resources in that cluster.

Q: Why not deploy the Node.js service in this article?

First, confirm that your local cluster works and learn to run and verify basic Kubernetes commands. This makes it easier to distinguish environment problems from application configuration problems if deployment fails in the next article.


🧪 Exercise

Complete these steps independently on your computer:

  1. Confirm that Docker, kind, and kubectl are available.
  2. Create a Kubernetes cluster named node-course.
  3. Run kubectl get nodes and confirm the node is Ready.
  4. Create a Namespace named course using YAML.
  5. Check the result with kubectl get namespace course.

Success criteria: You can see a ready node and the course Namespace with status Active, and explain the roles of kind, kubectl, nodes, and Namespaces.


🎉 Your local Kubernetes environment is ready, and you can use kubectl to create, inspect, and verify basic resources. Next, you will deploy a real Node.js service to this cluster.