安装 openssh-server,提供远程连接
sudo apt install -y openssh-server
修改ssh配置文件
sudo vi /etc/ssh/sshd_config
允许root用户远程连接:PermitRootLogin yes
重启 ssh
sudo systemctl restart ssh
卸载默认的vim
sudo apt-get remove vim-common
安装vim
apt-get install vim
设置主机名
sudo echo k8s-node-2 > /etc/hostname
编辑 hosts
sudo vim /etc/hosts
在hosts中追加:
192.168.136.133 k8s-master-2
192.168.136.134 k8s-node-2
关闭防火墙
sudo ufw enable sudo ufw allow 6443 sudo ufw status
关闭交换空间
sudo swapoff -a && sudo sed -i 's/^\/swap.img\(.*\)$/#\/swap.img \1/g' /etc/fstab && free
安装docker
sudo apt-get remove docker docker-engine docker.io containerd runc sudo apt-get update sudo apt-get install -y ca-certificates curl gnupg lsb-release 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 \ 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 systemctl list-unit-files | grep docker 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 sudo sed -i "s#registry.k8s.io/pause#registry.cn-hangzhou.aliyuncs.com/google_containers/pause#g" /etc/containerd/config.toml sudo sed -i "s#SystemdCgroup = false#SystemdCgroup = true#g" /etc/containerd/config.toml sudo systemctl enable --now containerd.service sudo systemctl restart 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 所需依赖
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-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
以上所有命令master,node都需要执行
master需要单独执行:
#该命令执行完会输出一条join命令,需要node节点执行,需要复制保存下载 sudo kubeadm init --image-repository=registry.aliyuncs.com/google_container
复制输出的join命令
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
一些查看命令
#查看集群信息 kubectl cluster-info #查看pod信息 kubectl get pods --all-namespaces -o wide #查看节点信息 kubectl get nodes #查看cs信息 kubectl get cs
配置网络
标签:get,sudo,apt,etc,systemctl,docker,k8s,安装
From: https://www.cnblogs.com/excellencesy/p/17023029.html