Skip to content

Commit dada5fa

Browse files
authored
Merge pull request #26 from bashtools/0.8.25
Run previous k8s version and support Intel Mac
2 parents d6f720b + b8dc862 commit dada5fa

11 files changed

+632
-532
lines changed

BUILD.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,18 @@ Build prebuilt image for upload and check version as it's building:
3434
```
3535
mok build image --tailf
3636
```
37-
Tag and upload:
37+
Tag and upload for Arm:
3838
```
39-
sudo podman tag localhost/local/mok-image_linux:1.32.0 docker.io/myownkind/mok-image_linux:1.32.0
39+
VERSION=1.32.2
40+
sudo podman tag localhost/local/mok-image_arm64:${VERSION} docker.io/myownkind/mok-image_arm64:${VERSION}
4041
sudo podman login docker.io
41-
sudo podman push docker.io/myownkind/mok-image_linux:1.32.0
42+
sudo podman push docker.io/myownkind/mok-image_linux:${VERSION}
4243
```
43-
or
44+
Tag and upload for Intel:
4445
```
45-
podman -c mok-machine tag localhost/local/mok-image_macos:1.32.0 docker.io/myownkind/mok-image_macos:1.32.0
46-
podman -c mok-machine login docker.io
47-
podman -c mok-machine push docker.io/myownkind/mok-image_macos:1.32.0
46+
VERSION=1.32.2
47+
podman tag localhost/local/mok-image_x86_64:${VERSION} docker.io/myownkind/mok-image_x86_64:${VERSION}
48+
podman login docker.io
49+
podman push docker.io/myownkind/mok-image_x86_64:${VERSION}
4850
```
4951

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
VERSION = 0.8.24
1+
VERSION = 0.8.25
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 macos.sh \
8+
cd src && ( echo '#!/usr/bin/env bash'; cat macos.sh arch.sh \
99
lib/parser.sh globals.sh error.sh util.sh getcluster.sh machine.sh machinestop.sh \
1010
machinestart.sh machinecreate.sh machinelist.sh machinedestroy.sh machinesetup.sh \
1111
exec.sh deletecluster.sh createcluster.sh versions.sh containerutils.sh \
@@ -21,7 +21,7 @@ package: mok.deploy
2121

2222
.PHONY: install
2323
install: all
24-
install mok.deploy /usr/local/bin/mok
24+
sudo install mok.deploy /usr/local/bin/mok
2525

2626
.PHONY: uninstall
2727
uninstall:

README.md

+20-13
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,39 @@ Current kubernetes version: 1.32.1
77

88
## TL;DR Quick Start
99

10+
Install:
11+
1012
```bash
1113
curl -O https://raw.githubusercontent.com/bashtools/mok/refs/heads/master/package/mok
1214
chmod +x mok
1315
sudo mv mok /usr/local/bin/
16+
```
17+
18+
Create cluster:
19+
20+
```
1421
mok build image --get-prebuilt-image
1522
mok create cluster myk8s --masters 1 --publish
23+
```
24+
25+
Use cluser:
26+
27+
```
1628
export KUBECONFIG=/var/tmp/admin-myk8s.conf
1729
kubectl get nodes
1830
kubectl get pods --all-namespaces
1931
kubectl run --privileged --rm -ti alpine --image alpine /bin/sh
20-
mok delete cluster myk8s
2132
```
2233

23-
To ensure no resources are used on Mac OS afterwards, run `mok machine destroy`.
34+
Delete cluster:
35+
36+
```
37+
mok delete cluster myk8s
38+
```
2439

2540
## Requirements
2641

27-
**MacOS on Apple Silicon (M1, M2, ...)**
42+
**MacOS**
2843
* Mok will will install any required packages using Homebrew, and will prompt you before doing so.
2944
* To see exactly how and what will be installed, see `src/macos.sh`.
3045

@@ -45,16 +60,6 @@ sudo mv mok /usr/local/bin/
4560

4661
## Using Mok
4762

48-
### Add an alias (Linux only)
49-
50-
On Linux only, use `sudo mok ...` or create an alias so that only `mok` is needed:
51-
52-
```bash
53-
alias mok="sudo /usr/local/bin/mok"
54-
```
55-
56-
Note: Add the alias to your shell startup file (`.bash_profile` or `.zshrc`) to make it persistent
57-
5863
### Build a container image
5964

6065
```bash
@@ -100,6 +105,8 @@ mok machine -h
100105
mok delete cluster myk8s
101106
```
102107

108+
On Mac OS do, `mok machine stop`, to stop the podman machine and free up resources.
109+
103110
## To Uninstall mok completely
104111

105112
### Mac

package/mok

+547-502
Large diffs are not rendered by default.

src/arch.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# shellcheck shell=bash disable=SC2148
2+
3+
declare __mokostype
4+
5+
set_arch() {
6+
if [[ ${__mokostype} == "linux" ]]; then
7+
# Is this machine x86 or arm?
8+
if [[ $(uname -m) == "x86_64" ]]; then
9+
export __mokarch=x86_64
10+
elif [[ $(uname -m) == "aarch64" ]]; then
11+
export __mokarch=arm64
12+
fi
13+
elif [[ ${__mokostype} == "macos" ]]; then
14+
# Is this machine x86 or arm?
15+
if [[ $(uname -m) == "x86_64" ]]; then
16+
export __mokarch=x86_64
17+
elif [[ $(uname -m) == "arm64" ]]; then
18+
export __mokarch=arm64
19+
fi
20+
fi
21+
}
22+
23+
set_arch

src/buildimage.sh

+17-3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ build image options:
4343
Flags:
4444
--get-prebuilt-image - Instead of building a 'node' image
4545
locally, download it from a container registry instead.
46+
--k8sver VERSION - The Kubernetes version, e.g. "1.32.0" or "1.32.1".
47+
A previous version cannot be built from scratch. This option
48+
must be used with '--get-prebuilt-image'. To build a previous
49+
version of kubernetes it must be built with a previous version
50+
of mok.
4651
--tailf - Show the build output whilst building.
4752
4853
EnD
@@ -77,6 +82,10 @@ BI_process_options() {
7782
_BI[tailf]="${TRUE}"
7883
return "${OK}"
7984
;;
85+
--k8sver)
86+
_BI[k8sver]="$2"
87+
return "$(PA_shift)"
88+
;;
8089
--get-prebuilt-image)
8190
_BI[useprebuiltimage]="${TRUE}"
8291
return "${OK}"
@@ -124,6 +133,7 @@ _BI_new() {
124133
_BI[baseimagename]="mok-image"
125134
_BI[useprebuiltimage]="${FALSE}"
126135
_BI[dockerbuildtmpdir]=
136+
_BI[k8sver]="${K8SVERSION}"
127137

128138
# Program the parser's state machine
129139
PA_add_state "COMMAND" "build" "SUBCOMMAND" ""
@@ -163,12 +173,15 @@ _BI_build_container_image() {
163173
_BI_create_docker_build_dir || return
164174

165175
buildargs=$(_BI_get_build_args_for_latest) || return
166-
basename="${_BI[baseimagename]}_$(MA_ostype)"
167-
tagname="${K8SVERSION}"
176+
basename="${_BI[baseimagename]}_$(MA_arch)"
177+
tagname="${_BI[k8sver]}"
168178

169179
local imgprefix
170180
imgprefix=$(CU_imgprefix) || err || return
171181
if [[ ${_BI[useprebuiltimage]} == "${FALSE}" ]]; then
182+
# Each mok release can build the hardcoded version only
183+
# so reset the tagname to that version
184+
tagname="${K8SVERSION}"
172185
buildtype="create"
173186
cmd="docker build \
174187
-t "${imgprefix}local/${basename}:${tagname}" \
@@ -177,6 +190,7 @@ _BI_build_container_image() {
177190
${_BI[dockerbuildtmpdir]}/${_BI[baseimagename]}"
178191
text="Creating"
179192
else
193+
# We can download and run any available version
180194
buildtype="download"
181195
cmd="docker pull docker.io/myownkind/${basename}:${tagname}"
182196
text="Downloading"
@@ -254,7 +268,7 @@ _BI_modify_container_image() {
254268
# Write image
255269
local imgprefix tagname basename
256270
imgprefix=$(CU_imgprefix) || err || return
257-
basename="${_BI[baseimagename]}_$(MA_ostype)"
271+
basename="${_BI[baseimagename]}_$(MA_arch)"
258272
tagname="${K8SVERSION}"
259273
docker commit mok-build-modify "${imgprefix}local/${basename}:${tagname}" || err || return
260274

src/containerutils.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ CU_create_container() {
137137
err || return
138138
}
139139

140-
img="$(BI_baseimagename)_$(MA_ostype)"
140+
img="$(BI_baseimagename)_$(MA_arch)"
141141

142142
local imglocal="${_CU[imgprefix]}local/${img}"
143143
local imgremote="myownkind/${img}"

src/createcluster.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ create cluster [flags] options:
137137
--with-lb - Add a haproxy load balancer. The software will be installed
138138
and set up to reverse proxy to the master node(s), unless
139139
--skiplbsetup is used.
140-
--k8sver VERSION - Unimplemented.
140+
--k8sver VERSION - The Kubernetes version, e.g. "1.32.0" or "1.32.1".
141+
A previous version will need to be downloaded first with:
142+
mok build image --get-prebuilt-image --k8sver VERSION
141143
--masters NUM - The number of master containers to create.
142144
--workers NUM - The number of worker containers to create. When workers
143145
is zero then the master node taint will be removed from

src/globals.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# Args: None expected.
1111
_GL_new() {
1212

13-
declare -rg MOKVERSION="0.8.24"
13+
declare -rg MOKVERSION="0.8.25"
1414
declare -rg K8SVERSION="1.32.1"
1515
declare -rg GO_VERSION="1.23.4"
1616

src/main.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
declare -A _MA
66

77
# Defined in GL (globals.sh)
8-
declare OK ERROR STOP STDERR TRUE __mokostype
8+
declare OK ERROR STOP STDERR TRUE __mokostype __mokarch
99

1010
# Getters/Setters -------------------------------------------------------------
1111

@@ -31,6 +31,11 @@ MA_ostype() {
3131
printf '%s' "${_MA[ostype]}"
3232
}
3333

34+
# MA_ostype getter outputs the machine architecture.
35+
MA_arch() {
36+
printf '%s' "${_MA[arch]}"
37+
}
38+
3439
# Public Functions ------------------------------------------------------------
3540

3641
# main is the start point for this application.
@@ -144,6 +149,7 @@ _MA_new() {
144149
_MA[arg_0]="$0"
145150
_MA[arg_1]="$1"
146151
_MA[ostype]="${__mokostype}" # linux or macos
152+
_MA[arch]="${__mokarch}" # x86_64 or arm64
147153

148154
# Program the parser's state machine
149155
PA_add_state "COMMAND" "version" "END" "MA_version"

src/versions.sh

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ etcd:
125125
dataDir: /var/lib/etcd
126126
imageRepository: registry.k8s.io
127127
kind: ClusterConfiguration
128+
kubernetesVersion: v${_CC[k8sver]}
128129
networking:
129130
dnsDomain: cluster.local
130131
podSubnet: \${podsubnet}

0 commit comments

Comments
 (0)