By Kevin McAleer, 5 Minutes
Page last updated November 24, 2026

By the end of this lesson you will be able to point kubectl on your own computer at your K3s cluster, and use it to deploy, inspect, expose and delete a simple app.
kubectl is the command-line tool that talks to the Kubernetes API on your server. You describe what you want (“three copies of nginx”), and Kubernetes makes it so and keeps it that way. If a pod dies, the Deployment creates another.
flowchart LR
K["kubectl on your laptop"] -->|"HTTPS port 6443"| API["API server on pi-server"]
API --> D["Deployment<br/>hello-world"]
D --> RS["ReplicaSet"]
RS --> P1["Pod on pi-node1"]
RS --> P2["Pod on pi-node2"]
SVC["Service<br/>NodePort"] --> P1
SVC --> P2
K3s already includes kubectl on the server, but it is nicer to work from your own computer. Install the standard kubectl by following the instructions at kubernetes.io/docs/tasks/tools/ for your operating system, then check it with:
kubectl version --client
The kubeconfig at /etc/rancher/k3s/k3s.yaml is root-only, so scp as a normal user is refused. Instead, read it with sudo over SSH:
mkdir -p ~/.kube
ssh [email protected] "sudo cat /etc/rancher/k3s/k3s.yaml" > ~/.kube/config
chmod 600 ~/.kube/config
Inside the file, the server: line points to https://127.0.0.1:6443, which means “this computer”. The K3s docs tell you to replace that with your server’s address. Open the file in an editor and change it, or on Linux:
sed -i 's/127.0.0.1/192.168.1.100/' ~/.kube/config
On macOS use sed -i '' ... instead. Now test:
kubectl get nodes
You should see the same nodes as before, with no sudo and no k3s in front. Keep this file private: it gives full administrator access to your cluster.
kubectl get nodes -o wide
kubectl get pods -A
kubectl get pods -n kube-system
-A means all namespaces and -n picks one. Namespaces are folders for resources. K3s puts its own components in kube-system, and yours go in default unless you say otherwise.
kubectl create deployment hello-world --image=nginx --replicas=2
kubectl expose deployment hello-world --port=80 --type=NodePort
kubectl get pods -o wide
kubectl get svc hello-world
The Service line shows a port such as 80:3xxxx/TCP. The number after the colon is the NodePort, between 30000 and 32767. Open http://192.168.1.100:<nodeport> in your browser, using any node’s address, and you should see the nginx welcome page. NodePort opens that same port on every node.
kubectl describe pod <pod-name>
kubectl logs <pod-name>
kubectl exec -it <pod-name> -- sh
Replace <pod-name> with a name from get pods. Then delete a pod and watch the Deployment replace it:
kubectl delete pod <pod-name>
kubectl get pods
A new pod with a different name appears almost at once. This is Kubernetes keeping its promise of two replicas.
| Command | What it does |
|---|---|
kubectl get <thing> |
List pods, services, deployments, nodes |
kubectl describe <thing> <name> |
Details and recent events, the first stop for problems |
kubectl logs <pod> |
Output from a pod’s container |
kubectl apply -f file.yaml |
Create or update from a file |
kubectl delete -f file.yaml |
Remove what a file created |
kubectl scale deployment <name> --replicas=3 |
Change the number of copies |
Clean up when you are done:
kubectl delete service hello-world
kubectl delete deployment hello-world
Teachers: Learners sharing one cluster will all type
hello-worldand trip over each other. Give each learner a namespace (kubectl create namespace alice) and have them add-n aliceto every command. Also stress that the kubeconfig is an administrator key, so it should not be emailed or committed to Git.
nginx with three replicas and use get pods -o wide to see which nodes they run on.Running.kubectl create deployment demo --image=nginx --dry-run=client -o yaml and read the YAML it prints. Which fields could you change?kubectl says connection refused to 127.0.0.1:6443, or localhost:8080.~/.kube/config exists and its server: line holds the server’s real IP address.Why: The copied kubeconfig points at 127.0.0.1, which on your laptop is not the Pi.
ImagePullBackOff.kubectl describe pod <name>, read the Events, and check the image name and that it supports arm64.Quick quiz 1 of 3
What does kubectl get pods -A show?
-A is short for all namespaces.Quick quiz 2 of 3
What happens if you delete one pod owned by a Deployment?
Quick quiz 3 of 3
Why do you edit the server: line in the copied kubeconfig?
Comments