Getting Startedkubernetes

The easiest way to install Kubernetes on a Mac

So you want to install Kubernetes on your Mac? A quick way is to run Kubernetes on Docker, and the easiest way to get going is using Docker Desktop and Talos OS - Talos OS will install and configure Kubernetes on Docker for you. (Note that Docker Desktop does have support for Kubernetes built in, but it is an older version of Kubernetes, and limited to a single node cluster.) You can be up and exploring Kubernetes on Mac within 10 minutes, with all the advantages of an API managed, immutable, secure Kubernetes OS.

First, install Docker Desktop.

Run Docker, give it the access it asks for, and you'll see it chugging along in the menu bar. It will launch a wizard, which you can skip if you just want to run Talos and Kubernetes on your Mac.

A key component of Talos is talosctl, the CLI (Command Line Interface) which lets you interact with the OS running on your kubernetes nodes (virtual nodes in this case, but the same talosctl is used for Kubernetes on bare metal, VMWare, or cloud providers).

To get going with talosctl you need to download the latest release as shown below (or from Github here.)

curl -Lo /usr/local/bin/talosctl https://github.com/talos-systems/talos/releases/latest/download/talosctl-$(uname -s | tr "[:upper:]" "[:lower:]")-amd64
chmod +x /usr/local/bin/talosctl

Now, test if it’s working by running:

talosctl --help

Creating a local cluster is as simple as:

talosctl cluster create --wait  --endpoint 127.0.0.1;

This command will create a simple two node cluster, with one master node and one worker node. Note that when running Kubernetes on a MacOS system, you currently need to specify the endpoint address, as in the above, as docker node IPs are not routable from the Mac host. (It is not necessary to specify this for versions of talosctl 0.7 or later - but as of this writing that is not yet released.)

You can create a more complex kubernetes cluster on your Mac by passing in different parameters. e.g. to create a cluster with 3 masters and 2 workers, use:

talosctl cluster create --wait  --masters 3 --workers 2 --endpoint 127.0.0.1;

(Note that in order to install a new Talos OS based kubernetes cluster on the same Mac, you should talosctl cluster destroy the old cluster first, and rm kubeconfig, else you will run into naming conflicts. You can manually assign unique names and run multiple clusters - but it's certainly easier to just destroy the old cluster, then create a new cluster.)

The creation of the kubernetes cluster takes a while to process (5 minutes on my Macbook Pro for a two node cluster), and you can expect to see some errors, as below, where the installation system expects services to be up, but they take longer on a docker based system than expected. Note that once the services do start, the installation proceeds correctly.

talosctl cluster create --wait  --endpoint 127.0.0.1;

validating CIDR and reserving IP
generating PKI and tokens
downloading docker.io/autonomy/talos:v0.6.2
creating network talos-default
creating master nodes
creating worker nodes
waiting for etcd to be healthy: ...
waiting for etcd to be healthy: rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: EOF"
waiting for etcd to be healthy: 1 error occurred:
	* 10.5.0.2: service "etcd" not in expected state "Running": current state [Preparing] Running pre state
waiting for etcd to be healthy: 1 error occurred:
	* 10.5.0.2: service is not healthy: etcd
waiting for etcd to be healthy: OK
waiting for bootkube to finish: ...
waiting for bootkube to finish: 1 error occurred:
	* 10.5.0.2: service "bootkube" not in expected state ["Finished" "Skipped"]: current state [Running] Started task bootkube (PID 347) for container bootkube
waiting for bootkube to finish: OK
waiting for apid to be ready: ...
waiting for apid to be ready: OK
waiting for all k8s nodes to report: ...
waiting for all k8s nodes to report: OK
waiting for all k8s nodes to report ready: ...
waiting for all k8s nodes to report ready: OK
waiting for all control plane components to be ready: ...
waiting for all control plane components to be ready: expected number available for kube-apiserver to be 1, got 0
waiting for all control plane components to be ready: OK
waiting for kube-proxy to report ready: ...
waiting for kube-proxy to report ready: OK
waiting for coredns to report ready: ...
waiting for coredns to report ready: OK
waiting for all k8s nodes to report schedulable: ...
waiting for all k8s nodes to report schedulable: OK

real	5m53.204s
user	0m5.192s
sys	0m0.453s
SFRANCIS:Downloads stevefrancis$ 

As well as the command output, you can also watch the progress from the Docker dashboard (click the Docker icon in the menu bar and select Dashboard.) Click the node talos-default-master-1, and you will see the logs of the master node, and be able to watch services start:

Installing Kubernetes cluster on a mac

Once the cluster create command has exited successfully, you need to set the Kubernetes configuration so it knows how to reach the API server:

talosctl config nodes 10.5.0.2
talosctl kubeconfig .
kubectl --kubeconfig kubeconfig config set-cluster talos-default --server https://127.0.0.1:6443

Finally, we just need to modify the talosctl config to specify which nodes you want to get information on. Talosctl can operate on one or all the nodes in the cluster - this makes cluster wide commands much easier.

talosctl config nodes 10.5.0.2 10.5.0.3

Note that these are the default node addresses for a one master, one worker cluster. If you already have a variety of containers running, or created more master or worker nodes, you can verify the node addresses using docker inspect or talosctl cluster show

You now have a complete (albeit simple) kubernetes cluster running on your mac. You can use talosctl to operate and examine the nodes. Some commands to try are:

talosctl containers
talosctl logs 
talosctl containers -k
talosctl logs -k kubelet
talosctl services

For further options with talosctl see the getting started guide and the Git repo.

You can also explore kubernetes on your Mac with kubernetes commands (passing in the kubeconfig):

kubectl --kubeconfig=kubeconfig get nodes
NAME                   STATUS ROLES  AGE VERSION
talos-default-master-1 Ready  master 25h v1.19.0
talos-default-worker-1 Ready  none   25h v1.19.0

Also try:
kubectl --kubeconfig=kubeconfig get pods -A

There are other more flexible ways to run Kubernetes on MacOS - we'll explore a qemu based installation in a later article. But if you want to get Kubernetes on a Mac up and running quickly so you can start learning and testing - Docker and Talos OS is the way to do it!

Leave a Reply

Your email address will not be published. Required fields are marked *