Skip to content

Commit 12be29f

Browse files
authored
Make Mok easy to use on Mac OS silicon (#24)
Mac OS changes: * Adds a new 'machine' command to mok, for managing and setting up a Podman Machine. * Mok will prompt the user to create or start the machine with, `mok machine create` or `mok machine start`. * Mok now checks for the 5 homebrew packages it needs. * Mok installs homebrew if it's not installed already. * `mok build image --get-prebuilt-image` can now be used on Mac OS.
1 parent 4492025 commit 12be29f

19 files changed

+2278
-643
lines changed

BUILD.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,14 @@ mok build image --tailf
3737
```
3838
Tag and upload:
3939
```
40-
sudo podman tag localhost/local/mok-image:1.32.0 docker.io/myownkind/mok-image:1.32.0
40+
sudo podman tag localhost/local/mok-image_linux:1.32.0 docker.io/myownkind/mok-image_linux:1.32.0
4141
sudo podman login docker.io
42-
sudo podman push docker.io/myownkind/mok-image:1.32.0
42+
sudo podman push docker.io/myownkind/mok-image_linux:1.32.0
4343
```
44+
or
45+
```
46+
podman -c mok-machine tag localhost/local/mok-image_macos:1.32.0 docker.io/myownkind/mok-image_macos:1.32.0
47+
podman -c mok-machine login docker.io
48+
podman -c mok-machine push docker.io/myownkind/mok-image_macos:1.32.0
49+
```
50+

Makefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
VERSION = 0.8.22
1+
VERSION = 0.8.23
22

33
.PHONY: all
44
all: mok.deploy tags
55

66
mok.deploy: src/*.sh src/lib/*.sh mok-image mok-image/* mok-image/files/*
77
bash src/embed-dockerfile.sh
8-
cd src && ( echo '#!/usr/bin/env bash'; cat \
9-
lib/parser.sh globals.sh error.sh util.sh getcluster.sh \
8+
cd src && ( echo '#!/usr/bin/env bash'; cat macos.sh \
9+
lib/parser.sh globals.sh error.sh util.sh getcluster.sh machine.sh machinestop.sh \
10+
machinestart.sh machinecreate.sh machinelist.sh machinedestroy.sh machinesetup.sh \
1011
exec.sh deletecluster.sh createcluster.sh versions.sh containerutils.sh \
1112
buildimage.deploy lib/JSONPath.sh main.sh; \
1213
printf 'if [ "$$0" = "$${BASH_SOURCE[0]}" ] || [ -z "$${BASH_SOURCE[0]}" ]; then\n MA_main "$$@"\nfi\n' \

README.md

Lines changed: 82 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,82 @@
55

66
Current kubernetes version: 1.32.0
77

8-
## Requirements
8+
## TL;DR Quick Start
9+
10+
```bash
11+
curl -O https://raw.githubusercontent.com/bashtools/mok/refs/heads/master/package/mok
12+
chmod +x mok
13+
sudo mv mok /usr/local/bin/
14+
mok build image --get-prebuilt-image
15+
mok create cluster myk8s --masters 1 --publish
16+
export KUBECONFIG=/var/tmp/admin-myk8s.conf
17+
kubectl get nodes
18+
kubectl get pods --all-namespaces
19+
kubectl run --privileged --rm -ti alpine --image alpine /bin/sh
20+
mok delete cluster myk8s
21+
```
922

10-
**Fedora 41 Desktop/Server on x86_64 or AMD64**
11-
* Podman
12-
* 5 GB of free disk space
23+
To ensure no resources are used on Mac OS afterwards, run `mok machine destroy`.
1324

14-
**MacOS 14.7 (Sonoma) on Apple Silicon**
15-
* Podman
16-
* 5 GB of free disk space
25+
## Requirements
1726

18-
Mok may work on other versions of Linux or MacOS but I have only tested it on the above.
27+
**MacOS on Apple Silicon (M1, M2, ...)**
28+
* Mok will will install any required packages using Homebrew, and will prompt you before doing so.
29+
* To see exactly how and what will be installed, see `src/macos.sh`.
30+
31+
**Fedora Desktop or Server**
32+
* Install Podman.
1933

2034
## Install
2135

22-
Use `curl` and download `mok` to `/usr/local/bin`:
36+
### Installation for Linux and Mac
37+
38+
Use `curl` to download `mok` and move it to `/usr/local/bin`:
2339

2440
```bash
2541
curl -O https://raw.githubusercontent.com/bashtools/mok/refs/heads/master/package/mok
2642
chmod +x mok
2743
sudo mv mok /usr/local/bin/
2844
```
2945

30-
or use `git` and `make` and install to `/usr/local/bin`:
46+
## Using Mok
47+
48+
### Add an alias (Linux only)
49+
50+
On Linux only, use `sudo mok ...` or create an alias so that only `mok` is needed:
3151

3252
```bash
33-
git clone https://github.com/bashtools/mok.git
34-
cd mok
35-
sudo make install
53+
alias mok="sudo /usr/local/bin/mok"
3654
```
3755

38-
### First use
39-
40-
For linux users: `alias mok="sudo /usr/local/bin/mok"`
56+
Note: Add the alias to your shell startup file (`.bash_profile` or `.zshrc`) to make it persistent
4157

42-
Build the latest image:
58+
### Build a container image
4359

4460
```bash
45-
mok build image
61+
mok build image --get-prebuilt-image
4662
```
4763

48-
### Create a multi node kuberenetes cluster
64+
### Create a single node kuberenetes cluster
4965

5066
```bash
51-
mok create cluster myk8s --masters 1 --workers 1
67+
mok create cluster myk8s --masters 1 --publish
5268
```
5369

70+
For Mac users `--publish` must be used - but it's optional for Linux users:
71+
5472
### Run some kubectl commands
5573

74+
Naturally, the [kubectl command](https://kubernetes.io/docs/tasks/tools/) is needed for this.
75+
5676
```bash
5777
export KUBECONFIG=/var/tmp/admin-myk8s.conf
5878
kubectl get nodes
5979
kubectl get pods --all-namespaces
6080
```
6181

6282
```bash
63-
# --privileged is required if you want to `ping`
83+
# --privileged is required if you want to `ping` a host
6484
kubectl run --privileged --rm -ti alpine --image alpine /bin/sh
6585
```
6686

@@ -69,6 +89,9 @@ kubectl run --privileged --rm -ti alpine --image alpine /bin/sh
6989
```bash
7090
mok -h
7191
mok create -h
92+
mok build -h
93+
mok machine -h
94+
# ... etc ...
7295
```
7396

7497
### Delete the cluster
@@ -77,61 +100,68 @@ mok create -h
77100
mok delete cluster myk8s
78101
```
79102

80-
### Uninstall mok completely
103+
## To Uninstall mok completely
104+
105+
### Mac
106+
107+
```bash
108+
mok machine destroy
109+
```
110+
111+
If `mok` installed Homebrew, then remove homebrew and all its installed packages with:
112+
113+
```
114+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
115+
```
116+
117+
Then to completely remove any left over directories run:
118+
119+
```
120+
sudo rm -rf /opt/homebrew
121+
```
122+
123+
Finally, delete `mok`, with:
81124

82125
```bash
83126
sudo rm /usr/local/bin/mok
127+
```
128+
129+
### Linux
84130

85-
# If you used git and make delete the git repo
131+
```bash
132+
sudo rm /usr/local/bin/mok
133+
134+
# If you used git and make, then delete the git repo
86135
rm -rf mok/
87136
```
88137

89138
Then delete the podman images that were built by `mok build`.
90139

91140
## Known Issues
92141

93-
**Fedora and MacOS:**
94142
* With multiple master nodes only the first master is set up
95143
* Currently only single node clusters can be stopped and restarted
96-
97-
**MacOS only:**
98-
* A recent version of Bash is required.
99-
* Use homebrew to install `bash` and `gawk`
100-
* add `eval "$(/opt/homebrew/bin/brew shellenv)` to the end of your `.zprofile` or `.bash_profile` so that
101-
brew installed files are found first.
102-
* To be able to use `kubectl` from the host machine and to be able to modify `nf_conntrack_max` the machine needs to be created with:
103-
```bash
104-
podman machine init --rootful --user-mode-networing
105-
```
106-
* This allows a kubernetes cluster to be created with the `--publish` option, for example:
107-
```bash
108-
mok create cluster myk8s 1 0 --publish
109-
```
110-
Then the commands in the 'Run some kubectl commands' section above will work without any modification.
111-
* `kube-proxy` requires a correctly set `nf_conntrack_max`. If it's incorrect then mok will supply the command to correct it and will also suggest the following commands be run:
112-
```
113-
# WARNING - This will delete all your existing pods/containers and anything else in the podman machine:
114-
podman machine stop
115-
podman machine rm
116-
podman machine init --now --rootful --user-mode-networing
117-
podman machine ssh modprobe nf_conntrack
118-
podman machine ssh sysctl -w net.netfilter.nf_conntrack_max=163840
119-
```
144+
* For Mac, if you installed Homebrew with `mok` then you should run
145+
`/opt/homebrew/bin/brew doctor` and follow the instructions shown there if
146+
you want to use Homebrew outside of Mok, or if you want to run the utilities
147+
that mok installed (podman for example).
120148

121149
## Some Features
122150

151+
* Podman Desktop is not required
152+
* On Mac OS all the required packages are installed for you
153+
* On Mac OS it uses a non-default podman machine, so won't mess up your existing podman installation
123154
* Builds kubernetes master and worker nodes in containers
124155
* Very simple to use without need for YAML files
125156
* After creating the image a single node cluster builds in under 60 seconds
126157
* For multi-node clusters the 'create cluster' command returns only when kubernetes is completely ready, with all nodes and pods up and ready.
127158
* Can skip setting up kubernetes on the master and/or worker node (good for learning!)
128159
* In this case the set-up scripts are placed in `/root` in the containers and can be run by hand
129160
* Can do kubernetes the hard way (see [kthwic](https://github.com/my-own-kind/kubernetes-the-hard-way-in-containers))
130-
* `mok build` and `mok create` can show extensive logs with `--tailf`
161+
* `mok build` and `mok create` can show extensive kubernetes logs with `--tailf`
131162

132163
* [Full Documentation](https://github.com/bashtools/mokctl-docs/tree/master/docs)
133164

134-
## Support
165+
## Support Mok
135166

136-
Follow:
137-
[Mok on BlueSky](https://bsky.app/profile/github-mok.bsky.social)
167+
Follow [Mok on BlueSky](https://bsky.app/profile/github-mok.bsky.social) or give Mok a star.

0 commit comments

Comments
 (0)