Kubernetes
Run containers and local Kubernetes on macOS with Podman, Podman Desktop, kubectl and minikube, and describe workloads in Kubernetes YAML.
4 min readUpdated
Kubernetes runs containers across a cluster and is configured with declarative YAML manifests. For local work on macOS, Podman replaces Docker as the container engine, Podman Desktop gives it a GUI, kubectl talks to a cluster, and minikube provides a single-node cluster on your machine. This note installs each of them with Homebrew and lists the commands used most.
The Podman tools map to the Docker ones like this:
| Docker | Podman |
|---|---|
docker |
podman |
| Docker Desktop | Podman Desktop |
| Docker Compose, Docker Swarm | podman compose, Kubernetes YAML |
Set up Podman
Podman manages OCI containers and pods without a daemon. On macOS containers run in a Linux virtual machine that Podman manages for you.
Install Podman, then create and start the virtual machine:
brew install podmanpodman machine init --cpus 2 --memory 2048 --disk-size 20podman machine start--memory is in MiB and --disk-size in GiB. Without the options, podman machine init uses default sizes.
To make the rootful connection to the machine the default, so that containers run as root inside the VM, set it and check that Podman answers:
podman system connection default podman-machine-default-rootpodman infoManage the machine with these commands:
# Stop the virtual machinepodman machine stop# Open a shell in the default machine (podman-machine-default)podman machine ssh# Remove the virtual machinepodman machine rmUse common Podman commands
Search for an image and run it interactively:
podman search busyboxpodman run -it docker.io/library/busyboxBuild an image from a Dockerfile (here the official nginx Dockerfile, referenced by URL) and run it in the background with container port 80 published on port 8080:
podman build -t nginx https://raw.githubusercontent.com/nginxinc/docker-nginx/594ce7a8bc26c85af88495ac94d5cd0096b306f7/mainline/buster/Dockerfilepodman run -d -p 8080:80 nginxPush the image to a registry such as Quay. Replace USERNAME with your account:
# Log in to quay.iopodman login quay.io# Tag the local image with the registry pathpodman tag localhost/nginx quay.io/USERNAME/nginx# Push itpodman push quay.io/USERNAME/nginxInspect images and containers:
# Show low-level information about an image or containerpodman inspect quay.io/USERNAME/nginx# List running containerspodman psInstall Podman Desktop
Podman Desktop is a GUI to browse, manage and inspect containers, images and pods:
brew install podman-desktopDescribe workloads in Kubernetes YAML
Instead of a Compose file, you can describe containers as Kubernetes objects in YAML. The same file then works with kubectl on a real cluster and with Podman locally (podman kube play deployment.yaml runs the pods it describes).
kubectl reads the object description from the YAML file and converts it to JSON for the API request. The example below is a Deployment that keeps three replicas of an nginx pod running, selected by the labels app: hostname and version: v101:

The image uses apiVersion: extensions/v1beta1, which Kubernetes 1.16 removed for Deployments. On current clusters the same Deployment uses apps/v1:
apiVersion: apps/v1kind: Deploymentmetadata: name: hostname-101-deploymentspec: replicas: 3 selector: matchLabels: app: hostname version: v101 template: metadata: labels: app: hostname version: v101 spec: containers: - name: nginx-hostname image: kubegoldenguide/nginx-hostname:1.0.1 ports: - containerPort: 80Create or update the Deployment from a local path or a URL:
kubectl apply -f deployment.yamlInstall and check kubectl
kubectl is the Kubernetes command-line client. Install it (kubernetes-cli is the same Homebrew formula) and check the version:
brew install kubectlkubectl version --clientCheck that kubectl is configured by asking for the cluster state:
kubectl cluster-infoIf you see a message like the following, kubectl is not configured or cannot reach a cluster:
The connection to the server <server-name:port> was refused - did you specify the right host or port?To run a cluster on your laptop, install a tool such as minikube first (next section) and run the commands again. If kubectl cluster-info returns a URL but you still cannot reach the cluster, dump the detailed cluster state:
kubectl cluster-info dumpRun a local cluster with minikube
minikube runs a single-node Kubernetes cluster locally, for learning and development. Install it and start a cluster with the default driver:
brew install minikubeminikube startTo choose the virtualisation driver explicitly:
# Start minikube with the QEMU driverminikube start --driver=qemu# Start minikube with the Podman driverminikube start --driver=podman# Make Podman the default driverminikube config set driver podmanminikube’s documentation still marks the Podman driver as experimental.
Use rootless Podman
By default minikube runs Podman with sudo. To use Podman without sudo (rootless Podman), set the rootless property:
minikube config set rootless trueWith rootless Podman, minikube recommends the containerd container runtime:
minikube start --driver=podman --container-runtime=containerd