k8s相关内容
-
安装 openssh-server,提供远程连接
sudo apt install -y openssh-server
# 修改root用户的密码 sudo passwd root
# 修改ssh配置文件 sudo vi /etc/ssh/sshd_config
# 允许root用户远程连接 PermitRootLogin yes
# 重启 ssh sudo systemctl restart ssh # /etc/init.d/ssh restart
-
使用 root 用户执行以下命令
-
安装 vim
sudo apt install -y vim
-
安装 vim
sudo apt install -y wget
-
将主机名指向本机IP,主机名只能包含:字母、数字、-(横杠)、.(点)
- 获取主机名
hostname
- 临时设置主机名
hostname 主机名
- 永久设置主机名
sudo echo '主机名' > /etc/hostname
- 编辑 hosts
sudo vim /etc/hosts
- 获取主机名
-
关闭防火墙
-
关闭交换空间
sudo swapoff -a sudo sed -i 's/.*swap.*/#&/' /etc/fstab
-
安装 Docker
sudo apt-get remove docker docker-engine docker.io containerd runc sudo apt-get update # 更新apt包索引并安装包以允许apt通过 HTTPS 使用存储库: sudo apt-get install -y ca-certificates curl gnupg lsb-release # 添加 Docker 的官方 GPG 密钥 sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg # 设置稳定存储库 # echo \ # "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ # $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null # 由于docker暂未提供 22.10 的安装包,这里使用 22.04 的安装包 echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ jammy stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo chmod a+r /etc/apt/keyrings/docker.gpg sudo apt-get update # 安装 Docker 引擎 sudo apt-get update sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin sudo docker info # sudo systemctl status docker sudo systemctl list-unit-files | grep docker # 启动 docker 时,会启动 containerd # sudo systemctl status containerd.service sudo systemctl stop containerd.service sudo cp /etc/containerd/config.toml /etc/containerd/config.toml.bak sudo containerd config default > $HOME/config.toml sudo cp $HOME/config.toml /etc/containerd/config.toml # 修改 /etc/containerd/config.toml 文件后,要将 docker、containerd 停止后,再启动 sudo sed -i "s#registry.k8s.io/pause#registry.cn-hangzhou.aliyuncs.com/google_containers/pause#g" /etc/containerd/config.toml # https://kubernetes.io/zh-cn/docs/setup/production-environment/container-runtimes/#containerd-systemd # 确保 /etc/containerd/config.toml 中的 disabled_plugins 内不存在 cri sudo sed -i "s#SystemdCgroup = false#SystemdCgroup = true#g" /etc/containerd/config.toml sudo systemctl enable --now containerd.service # sudo systemctl status containerd.service # sudo systemctl status docker.service sudo systemctl restart docker.service # sudo systemctl status docker.service sudo systemctl enable docker.service systemctl list-unit-files | grep docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://hnkfbj7x.mirror.aliyuncs.com"], "exec-opts": ["native.cgroupdriver=systemd"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker sudo docker info
systemctl status docker.service
systemctl status containerd.service
-
安装 k8s 1.25.3 所需依赖
文档:Kubernetes镜像sudo apt-get update && sudo apt-get install -y apt-transport-https curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
sudo vim /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
sudo apt-get update # sudo apt-cache madison kubelet # sudo apt-cache madison kubeadm # sudo apt-cache madison kubectl sudo apt-get install -y kubelet=1.25.3-00 kubeadm=1.25.3-00 kubectl=1.25.3-00 sudo systemctl daemon-reload sudo systemctl restart kubelet sudo systemctl enable kubelet
sudo systemctl status kubelet
-
已上命令需要在控制面板与node节点执行,并确保没有错误与警告
-
已上命令需要在控制面板与node节点执行,并确保没有错误与警告
-
已上命令需要在控制面板与node节点执行,并确保没有错误与警告
-
控制面板:初始化
sudo kubeadm init --image-repository=registry.aliyuncs.com/google_containers mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config kubectl cluster-info # 初始化失败后,可进行重置,重置命令:kubeadm reset # 执行成功后,会出现类似下列内容: # kubeadm join 192.168.61.142:6443 --token 66l0ur.370hug1iiyra1or9 \ # --discovery-token-ca-cert-hash sha256:3f3bacdbc4162511909b066ffccf06226d2c53fb6cefbc9b92789260d001359e
-
控制面板:
kubectl get pods --all-namespaces -o wide
kubectl get nodes
kubectl get cs