3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

kubectlをM1 Mac向けにコンパイルする

Last updated at Posted at 2020-12-31

2020年時点でkubectlをM1 Mac向けにコンパイルする仕組みはない

Ref. https://github.com/kubernetes/kubernetes/issues/97550

PRも作られてるがなんか中途半端でコメントを入れておいたがすぐに取り込まれるかは不明なので、先にpatchを当ててやる方法を作ってしまう。

diffはこうだ。

diff.patch
diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh
index bef1d837703..768aa1e867a 100755
--- a/hack/lib/golang.sh
+++ b/hack/lib/golang.sh
@@ -49,6 +49,7 @@ readonly KUBE_SUPPORTED_CLIENT_PLATFORMS=(
   linux/s390x
   linux/ppc64le
   darwin/amd64
+  darwin/arm64
   windows/amd64
   windows/386
 )
@@ -62,6 +63,7 @@ readonly KUBE_SUPPORTED_TEST_PLATFORMS=(
   linux/s390x
   linux/ppc64le
   darwin/amd64
+  darwin/arm64
   windows/amd64
 )
 
@@ -213,11 +215,13 @@ kube::golang::setup_platforms() {
     if [[ "${KUBE_BUILDER_OS:-}" == "darwin"* ]]; then
       KUBE_TEST_PLATFORMS=(
         darwin/amd64
+        darwin/arm64
         linux/amd64
       )
       readonly KUBE_TEST_PLATFORMS
       KUBE_CLIENT_PLATFORMS=(
         darwin/amd64
+        darwin/arm64
         linux/amd64
       )
       readonly KUBE_CLIENT_PLATFORMS
diff --git a/test/typecheck/main.go b/test/typecheck/main.go
index ffe5085b0d5..4d631f205ec 100644
--- a/test/typecheck/main.go
+++ b/test/typecheck/main.go
@@ -51,7 +51,7 @@ var (
 		"darwin/amd64", "linux/arm",
 		"linux/386", "windows/amd64",
 		"linux/arm64", "linux/ppc64le",
-		"linux/s390x",
+		"linux/s390x", "darwin/arm64",
 	}
 
 	// directories we always ignore
  

まずは公式手順通りにk/kをcloneしてくる。

mkdir -p $GOPATH/src/k8s.io
cd $GOPATH/src/k8s.io
git clone https://github.com/kubernetes/kubernetes
cd kubernetes

できたらpatchをあてる

curl -LO https://gist.githubusercontent.com/inductor/d944f90cb277d077fb8b737ff74b9cf2/raw/a276fcad07a693b60679d473720718761c4de94d/mac-m1.patch
git apply mac-m1.patch

コンパイルして、kubectlが出力され実行できることを確認

make kubectl
ls -l _output/bin/kubectl
-rwxr-xr-x  1 inductor  staff 44870050  12 31 10:30 _output/bin/kubedctl

kubectlが実行できることを確認

kubectl get pod
No resources found in default namespace.

わいわい

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?