跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

k8s.yaml

266 行 · 10.1 KB历史下载
1# Deploy kubernetes via kubeadm.
2# $ limactl start ./k8s.yaml
3# $ limactl shell k8s kubectl
4
5# It can be accessed from the host by exporting the kubeconfig file;
6# the ports are already forwarded automatically by lima:
7#
8# $ export KUBECONFIG=$(limactl list k8s --format 'unix://{{.Dir}}/copied-from-guest/kubeconfig.yaml')
9# $ kubectl get no
10# NAME STATUS ROLES AGE VERSION
11# lima-k8s Ready control-plane,master 44s v1.22.3
12
13# A multi-node cluster can be created by starting multiple instances of this template
14# connected via the `lima:user-v2` network.
15#
16# $ limactl start --name k8s --network lima:user-v2 template:k8s
17# $ limactl shell k8s sudo kubeadm token create --print-join-command
18# (The parameters for the start command printed here)
19#
20# $ limactl start --name k8s-1 --network lima:user-v2 template:k8s \
21# --param url="<ADDRESS_FROM_ABOVE>" --param token="<TOKEN_FROM_ABOVE>" \
22# --param discoveryTokenCaCertHash="<DISCOVERY_TOKEN_CA_CERT_HASH_FROM_ABOVE>"
23
24minimumLimaVersion: 2.0.0
25
26base: template:_images/ubuntu-lts
27
28# Mounts are disabled in this template, but can be enabled optionally.
29mounts: []
30containerd:
31 system: true
32 user: false
33provision:
34# See <https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/>
35- mode: system
36 script: |
37 #!/bin/bash
38 set -eux -o pipefail
39 command -v kubeadm >/dev/null 2>&1 && exit 0
40 # Install and configure prerequisites
41 cat <<EOF | sudo tee /etc/modules-load.d/containerd.conf
42 overlay
43 br_netfilter
44 EOF
45 modprobe overlay
46 modprobe br_netfilter
47 cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
48 net.bridge.bridge-nf-call-iptables = 1
49 net.ipv4.ip_forward = 1
50 net.bridge.bridge-nf-call-ip6tables = 1
51 EOF
52 sysctl --system
53 # Installing kubeadm, kubelet and kubectl
54 export DEBIAN_FRONTEND=noninteractive
55 apt-get update
56 apt-get install -y --no-upgrade ca-certificates curl gnupg
57 STABILITY="{{.Param.stability}}"
58 {{if eq .Param.release "stable" }}
59 RELEASE=$(curl -L -s https://dl.k8s.io/release/stable.txt | cut -d'.' -f1-2)
60 {{else}}
61 RELEASE="{{.Param.release}}"
62 {{end}}
63 {{- if .Param.proxy }}
64 echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] {{.Param.proxy}}/HTTPS///pkgs.k8s.io/core:/${STABILITY}:/${RELEASE}/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
65 {{- else}}
66 echo "deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/${STABILITY}:/${RELEASE}/deb/ /" | sudo tee /etc/apt/sources.list.d/kubernetes.list
67 {{- end}}
68 curl -fsSL https://pkgs.k8s.io/core:/${STABILITY}:/${RELEASE}/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
69 apt-get update
70 apt-get install -y kubelet kubeadm kubectl && apt-mark hold kubelet kubeadm kubectl
71 systemctl enable --now kubelet
72# See <https://kubernetes.io/docs/setup/production-environment/container-runtimes/>
73- mode: system
74 script: |
75 #!/bin/bash
76 set -eux -o pipefail
77 [ -e /etc/containerd/conf.d/k8s.toml ] && exit 0
78 mkdir -p /etc/containerd/conf.d
79 # Configuring the systemd cgroup driver
80 # Overriding the sandbox (pause) image
81 cat <<EOF >/etc/containerd/conf.d/k8s.toml
82 version = 2
83 [plugins]
84 [plugins."io.containerd.grpc.v1.cri"]
85 sandbox_image = "$(kubeadm config images list | grep pause | sort -r | head -n1)"
86 [plugins."io.containerd.grpc.v1.cri".containerd]
87 [plugins."io.containerd.grpc.v1.cri".containerd.runtimes]
88 [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
89 runtime_type = "io.containerd.runc.v2"
90 [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
91 SystemdCgroup = true
92 {{- if .Param.mirror }}
93 [plugins."io.containerd.grpc.v1.cri".registry]
94 config_path = "/etc/containerd/certs.d"
95 {{- end}}
96 [plugins."io.containerd.cri.v1.runtime".cni]
97 bin_dirs = ["/usr/local/libexec/cni","/opt/cni/bin"]
98 EOF
99 {{if .Param.mirror }}
100 mkdir -p /etc/containerd/certs.d/_default
101 cat <<EOF >/etc/containerd/certs.d/_default/hosts.toml
102 [host."{{.Param.mirror}}"]
103 capabilities = ["pull", "resolve"]
104 EOF
105 {{end}}
106 systemctl restart containerd
107# See <https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/>
108- mode: system
109 script: |
110 #!/bin/bash
111 set -eux -o pipefail
112 test -e /etc/kubernetes/admin.conf && exit 0
113 export KUBECONFIG=/etc/kubernetes/admin.conf
114 {{if not ( and .Param.url .Param.token )}}
115 systemctl stop kubelet
116 VERSION="{{.Param.version}}"
117 kubeadm config images list --kubernetes-version="${VERSION}"
118 kubeadm config images pull --kubernetes-version="${VERSION}" --cri-socket=unix:///run/containerd/containerd.sock
119 systemctl start kubelet
120 # Initializing your control-plane node
121 cat <<EOF >/etc/kubeadm-config.yaml
122 kind: InitConfiguration
123 apiVersion: kubeadm.k8s.io/v1beta4
124 nodeRegistration:
125 criSocket: unix:///run/containerd/containerd.sock
126 ---
127 kind: ClusterConfiguration
128 apiVersion: kubeadm.k8s.io/v1beta4
129 kubernetesVersion: "${VERSION}"
130 apiServer:
131 certSANs: # --apiserver-cert-extra-sans
132 - "127.0.0.1"
133 networking:
134 podSubnet: "10.244.0.0/16" # --pod-network-cidr
135 ---
136 kind: KubeletConfiguration
137 apiVersion: kubelet.config.k8s.io/v1beta1
138 cgroupDriver: systemd
139 EOF
140 kubeadm init --config /etc/kubeadm-config.yaml
141 {{else}}
142 cat <<EOF >/etc/kubeadm-config.yaml
143 kind: JoinConfiguration
144 apiVersion: kubeadm.k8s.io/v1beta4
145 nodeRegistration:
146 criSocket: unix:///run/containerd/containerd.sock
147 discovery:
148 bootstrapToken:
149 apiServerEndpoint: "{{.Param.url}}"
150 token: "{{.Param.token}}"
151 caCertHashes:
152 - "{{.Param.discoveryTokenCaCertHash}}"
153 EOF
154 kubeadm join --config /etc/kubeadm-config.yaml
155 {{end}}
156
157 {{if not ( and .Param.url .Param.token )}}
158 # Installing a Pod network add-on
159 {{if eq .Param.flannelVersion "latest" }}
160 kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
161 {{else}}
162 kubectl apply -f https://github.com/flannel-io/flannel/releases/download/{{.Param.flannelVersion}}/kube-flannel.yml
163 {{end}}
164 # Control plane node isolation
165 kubectl taint nodes --all node-role.kubernetes.io/control-plane-
166 # Symlink the kubeconfig file to the default location for kubectl
167 mkdir -p /root/.kube && ln -sf $KUBECONFIG /root/.kube/config
168 # Replace the server address with localhost, so that it works from the host.
169 # The original kubeconfig is kept unmodified, so that `kubeadm token create --print-join-command`
170 # can still print the reachable address.
171 sed -e "/server:/ s|https://.*:\([0-9]*\)$|https://127.0.0.1:\1|" $KUBECONFIG >/root/.kube/config.localhost
172 {{end}}
173- mode: system
174 script: |
175 #!/bin/bash
176 set -eux -o pipefail
177 # set up user config on control plane node
178 {{if not ( and .Param.url .Param.token )}}
179 export KUBECONFIG=/etc/kubernetes/admin.conf
180 mkdir -p {{.Home}}/.kube
181 cp -f $KUBECONFIG {{.Home}}/.kube/config
182 chown -R {{.User}} {{.Home}}/.kube
183 {{end}}
184probes:
185- description: "kubeadm to be installed"
186 script: |
187 #!/bin/bash
188 set -eux -o pipefail
189 if ! timeout 30s bash -c "until command -v kubeadm >/dev/null 2>&1; do sleep 3; done"; then
190 echo >&2 "kubeadm is not installed yet"
191 exit 1
192 fi
193 hint: |
194 See "/var/log/cloud-init-output.log" in the guest
195- description: "kubernetes images to be pulled"
196 script: |
197 #!/bin/bash
198 set -eux -o pipefail
199 {{if not ( and .Param.url .Param.token )}}
200 if ! timeout 30s bash -c "images=\"$(kubeadm config images list)\"; until for image in \$images; do sudo ctr -n k8s.io image inspect \$image >/dev/null; done; do sleep 3; done"; then
201 echo >&2 "k8s images are not pulled yet"
202 exit 1
203 fi
204 {{end}}
205- description: "kubeadm to be completed"
206 script: |
207 #!/bin/bash
208 set -eux -o pipefail
209 {{if not ( and .Param.url .Param.token )}}
210 if ! timeout 300s bash -c "until test -f /etc/kubernetes/admin.conf; do sleep 3; done"; then
211 echo >&2 "k8s is not running yet"
212 exit 1
213 fi
214 {{end}}
215 hint: |
216 The k8s kubeconfig file has not yet been created.
217- description: "kubernetes cluster to be running"
218 script: |
219 #!/bin/bash
220 set -eux -o pipefail
221 {{if not ( and .Param.url .Param.token )}}
222 if ! timeout 300s bash -c "until kubectl version >/dev/null 2>&1; do sleep 3; done"; then
223 echo >&2 "kubernetes cluster is not up and running yet"
224 exit 1
225 fi
226 {{end}}
227- description: "coredns deployment to be running"
228 script: |
229 #!/bin/bash
230 set -eux -o pipefail
231 {{if not ( and .Param.url .Param.token )}}
232 kubectl wait -n kube-system --timeout=180s --for=condition=available deploy coredns
233 {{end}}
234copyToHost:
235- guest: "/root/.kube/config.localhost"
236 host: "{{.Dir}}/copied-from-guest/kubeconfig.yaml"
237 skipIfMissing: true
238 deleteOnStop: true
239message: |
240 {{- if not ( and .Param.url .Param.token )}}
241 To run `kubectl` on the host (assumes kubectl is installed), run the following commands:
242 ------
243 export KUBECONFIG="{{.Dir}}/copied-from-guest/kubeconfig.yaml"
244 kubectl ...
245 ------
246 {{end -}}
247param:
248 # The proxy to use when pulling packages from k8s.io
249 # For a local proxy use for instance "http://host.lima.internal:3142"
250 proxy: ""
251 # The mirror to use when pulling images from registry
252 # For a local mirror use for instance "http://host.lima.internal:8080"
253 mirror: ""
254 # The stability can be either "stable" or "prerelease"
255 # <https://build.opensuse.org/project/subprojects/isv:kubernetes:core>
256 stability: "stable"
257 # The release can be either "stable" or "v1.xx" (branch)
258 # (stable version is found at: <https://dl.k8s.io/release/stable.txt>)
259 release: "v1.37"
260 # The k8s version can be either "stable" or "v1.xx.y"
261 version: "stable"
262 # The flannel version is either "latest" or "v0.xx.y"
263 flannelVersion: "v0.28.9"
264 url: ""
265 token: ""
266 discoveryTokenCaCertHash: ""