编写k8s二进制部署脚本
时间: 2023-05-24 16:03:05 浏览: 154
A:
首先,需要下载 kubernetes 的二进制包,并解压到本地。
然后,编写以下脚本:
```
#!/bin/bash
# 安装工具
apt-get update
apt-get install -y socat conntrack ipset
# 下载 kubernetes 的二进制包
VERSION=1.21.1
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v$VERSION/bin/linux/amd64/kube-apiserver"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v$VERSION/bin/linux/amd64/kube-controller-manager"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v$VERSION/bin/linux/amd64/kube-scheduler"
curl -LO "https://storage.googleapis.com/kubernetes-release/release/v$VERSION/bin/linux/amd64/kubectl"
# 授予权限
chmod +x kube-apiserver kube-controller-manager kube-scheduler kubectl
# 复制二进制文件到 /usr/local/bin 目录
mv kube-apiserver kube-controller-manager kube-scheduler kubectl /usr/local/bin/
# 创建 systemd unit 文件
touch /etc/systemd/system/kube-apiserver.service
cat > /etc/systemd/system/kube-apiserver.service <<EOF
[Unit]
Description=Kubernetes API Server
Documentation=https://github.com/kubernetes/kubernetes
[Service]
ExecStart=/usr/local/bin/kube-apiserver
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
touch /etc/systemd/system/kube-controller-manager.service
cat > /etc/systemd/system/kube-controller-manager.service <<EOF
[Unit]
Description=Kubernetes Controller Manager
Documentation=https://github.com/kubernetes/kubernetes
[Service]
ExecStart=/usr/local/bin/kube-controller-manager
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
touch /etc/systemd/system/kube-scheduler.service
cat > /etc/systemd/system/kube-scheduler.service <<EOF
[Unit]
Description=Kubernetes Scheduler
Documentation=https://github.com/kubernetes/kubernetes
[Service]
ExecStart=/usr/local/bin/kube-scheduler
Restart=always
User=root
[Install]
WantedBy=multi-user.target
EOF
# 启动服务
systemctl daemon-reload
systemctl start kube-apiserver kube-controller-manager kube-scheduler
```
阅读全文