# K3s-Install [Configuration Options](https://docs.k3s.io/installation/configuration) [Environment Variables](https://docs.k3s.io/reference/env-variables) :::info Rancher latest v2.8.3(2024/05) 支援的K3s最高版本只到v1.27 ::: :::info context 用的 Token 在 `/etc/rancher/k3s/k3s.yaml` 加入 Cluster 使用的 Token 在 `/var/lib/rancher/k3s/server/node-token` 也可以留存起來,第一次建立 Cluster 時就帶入 ::: ## 一般安裝 - 建立k3s server ``` bash curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" sh -s - --cluster-init ``` - 建立k3s server 並加入Cluster ``` bash curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" INSTALL_K3S_VERSION="v1.27.11+k3s1" K3S_URL=https://<Url>:6443 K3S_TOKEN="<Token>" sh -s - --cluster-init ``` - 建立k3s agent 並加入Cluster ``` bash curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="agent" INSTALL_K3S_VERSION="v1.27.11+k3s1" K3S_URL=https://<Url>:6443 K3S_TOKEN="<Token>" sh -s - ``` ## Ingress Controller 改用Nginx - 建立k3s server並取消安裝Traefik ``` bash curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" INSTALL_K3S_VERSION="v1.27.11+k3s1" K3S_TOKEN="<Token>" sh -s - --cluster-init --disable traefik ``` - Helm install Nginx ``` helm install ingress-nginx ingress-nginx \ --repo https://kubernetes.github.io/ingress-nginx \ --namespace kube-system ``` [Ingress-Nginx Controller](https://kubernetes.github.io/ingress-nginx/) - 透過Helm安裝Rancher需要修改Ingerss Yaml ``` spec: ingressClassName: nginx ``` ## kubectl autocomplete [kubectl Quick Reference](https://kubernetes.io/docs/reference/kubectl/quick-reference/) ``` bash source <(kubectl completion bash) # set up autocomplete in bash into the current shell, bash-completion package should be installed first. echo "source <(kubectl completion bash)" >> ~/.bashrc # add autocomplete permanently to your bash shell. ``` ## Air-Gap Install 下載安裝用sh ```sh curl -sfL https://get.k3s.io > install.sh\ ``` 到官方[Github](https://github.com/k3s-io/k3s/releases)下載所需的版本 ```sh wget https://github.com/k3s-io/k3s/releases/download/v1.30.1%2Bk3s1/k3s-airgap-images-amd64.tar.zst ``` 下載binary ```sh https://github.com/k3s-io/k3s/releases/download/v1.30.1%2Bk3s1/k3s ``` 將安裝用sh、壓縮檔、binary放入無連外網路的機器 ```sh INSTALL_K3S_SKIP_DOWNLOAD=true INSTALL_K3S_EXEC="server" ./install.sh --cluster-init ``` ## 安裝後參數更改 直接修改`/etc/systemd/system/k3s.service` 可使用參數請參考[官方文件](https://docs.k3s.io/cli/server) - `/etc/rancher/k3s/kubelet.config` 修改最多pod數量 ```yaml apiVersion: kubelet.config.k8s.io/v1beta1 kind: KubeletConfiguration maxPods: 220 ``` ``` ExecStart=/usr/local/bin/k3s \ server \ '--cluster-init' \ '--tls-san=120.114.75.221' \ '--kubelet-arg=config=/etc/rancher/k3s/kubelet.config' \ ``` 修改完成後`daemon-reload`及重啟k3s即可 ``` systemctl daemon-reload systemctl restart k3s ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up