kubectl is the command-line tool for interacting with a Kubernetes cluster. Use it from your computer to deploy microservices, inspect their resources, and remove them when testing is finished. Before deploying, check that kubectl is installed and connected to the cluster you intend to change. section 6.1 section 6.8.4
Get connected and verify the target:
- Run `kubectl version` to check the client and server versions. Docker Desktop includes kubectl when Kubernetes is enabled; on Linux, install kubectl separately. section 6.6
- Run `kubectl config current-context` before making changes. Use `kubectl config get-contexts` to list configured connections and `kubectl config use-context docker-desktop` to select the local Docker Desktop cluster. section 6.8.4
- For an Azure Kubernetes cluster, run `az aks get-credentials --resource-group <resource-group> --name <cluster>`, then check the current context again. Run `kubectl get pods` to test the connection; `kubectl get pods --namespace kube-system` also shows system pods. section 6.10.3
Deploy and check a microservice locally
With the local context selected and a deployment configuration ready, run `kubectl apply -f scripts/deploy.yaml`. The `-f` option supplies the YAML file; `apply` creates its requested objects in the cluster. Then run `kubectl get pods`, `kubectl get deployments`, and `kubectl get services`. A running pod, an available deployment, and a service indicate that the microservice was deployed. The service output also shows its exposed port. When testing is done, run `kubectl delete -f scripts/deploy.yaml` and use the same `get` commands to confirm the created objects are gone. section 6.8.5 section 6.8.7
The same workflow applies to a managed cluster, but publish the container image to a registry and point the YAML configuration at that image before applying it. Check the service output for an external IP when testing a cloud deployment. Production scripts can expand configuration templates and pipe them into kubectl, but practice the manual deployment first so you know what the automation is doing. section 7.12 section 10.9.2 section 10.9










