Skip to content

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:

Terminal window
brew install podman
podman machine init --cpus 2 --memory 2048 --disk-size 20
podman 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:

Terminal window
podman system connection default podman-machine-default-root
podman info

Manage the machine with these commands:

Terminal window
# Stop the virtual machine
podman machine stop
# Open a shell in the default machine (podman-machine-default)
podman machine ssh
# Remove the virtual machine
podman machine rm

Use common Podman commands

Search for an image and run it interactively:

Terminal window
podman search busybox
podman run -it docker.io/library/busybox

Build 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:

Terminal window
podman build -t nginx https://raw.githubusercontent.com/nginxinc/docker-nginx/594ce7a8bc26c85af88495ac94d5cd0096b306f7/mainline/buster/Dockerfile
podman run -d -p 8080:80 nginx

Push the image to a registry such as Quay. Replace USERNAME with your account:

Terminal window
# Log in to quay.io
podman login quay.io
# Tag the local image with the registry path
podman tag localhost/nginx quay.io/USERNAME/nginx
# Push it
podman push quay.io/USERNAME/nginx

Inspect images and containers:

Terminal window
# Show low-level information about an image or container
podman inspect quay.io/USERNAME/nginx
# List running containers
podman ps

Install Podman Desktop

Podman Desktop is a GUI to browse, manage and inspect containers, images and pods:

Terminal window
brew install podman-desktop

Describe 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:

Kubernetes Deployment manifest with three replicas, label selectors and an nginx-hostname container on port 80

The image uses apiVersion: extensions/v1beta1, which Kubernetes 1.16 removed for Deployments. On current clusters the same Deployment uses apps/v1:

deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: hostname-101-deployment
spec:
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: 80

Create or update the Deployment from a local path or a URL:

Terminal window
kubectl apply -f deployment.yaml

Install and check kubectl

kubectl is the Kubernetes command-line client. Install it (kubernetes-cli is the same Homebrew formula) and check the version:

Terminal window
brew install kubectl
kubectl version --client

Check that kubectl is configured by asking for the cluster state:

Terminal window
kubectl cluster-info

If 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:

Terminal window
kubectl cluster-info dump

Run 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:

Terminal window
brew install minikube
minikube start

To choose the virtualisation driver explicitly:

Terminal window
# Start minikube with the QEMU driver
minikube start --driver=qemu
# Start minikube with the Podman driver
minikube start --driver=podman
# Make Podman the default driver
minikube config set driver podman

minikube’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:

Terminal window
minikube config set rootless true

With rootless Podman, minikube recommends the containerd container runtime:

Terminal window
minikube start --driver=podman --container-runtime=containerd

References

Related notes

4 min readTürkçe

Ollama

GPU'suz, yalnız CPU ile çalışan makinelerde Ollama ile yerel LLM çalıştırma ve hızı belirleyen ayarlar.

  • AI & Data
  • DevOps & Containers
7 min readTürkçe

Podman

Podman kurulumu, rootless container'ları systemd ve Quadlet ile kullanıcı servisi olarak çalıştırma ve sık görülen hatalar.

  • DevOps & Containers
2 min read

Trivy

Install Trivy and scan project files, Git repositories, container images and Kubernetes workloads for vulnerabilities and misconfigurations.

  • Security
  • DevOps & Containers

Type to search the whole site.