在Ubuntu安装kubernetes
阅读原文时间:2023年07月09日阅读:2

1. 配置Docker

docker安装完成后需要配置cgroup驱动为systemd来增强稳定性

sudo vim /etc/docker/daemon.json


{
  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
      "max-size": "100m"
   },
  "storage-driver": "overlay2",
  "registry-mirrors": ["https://9cpn8tt6.mirror.aliyuncs.com"]
}


mkdir -p /etc/systemd/system/docker.service.d


systemctl daemon-reload
systemctl restart docker

1.关闭swap

/*暂时关闭*/
sudo swapoff -a


/*永久关闭*/
sudo vim /etc/fstab

2. 确保服务器的时区一致

1) 强制更改时区为上海

ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
bash -c "echo 'Asia/Shanghai' > /etc/timezone"

2) 安装ntpdate

apt-get install -y ntpdate

如果出现以下错误

E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?

执行2个命令解决

sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock

3) 使用阿里云的时间服务器更新

ntpdate ntp1.aliyun.com

1.添加apt key以及源

sudo apt update && sudo apt install -y apt-transport-https curl
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" >>/etc/apt/sources.list.d/kubernetes.list

2. 安装最新版kubelet

sudo apt update
sudo apt install -y kubelet=1.15.2-00 kubeadm=1.15.2-00 kubectl=1.15.2-00
sudo apt-mark hold kubelet=1.15.2-00 kubeadm=1.15.2-00 kubectl=1.15.2-00

3. 安装kubernetes集群

kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.19.4 | tee /etc/kube-server-key

4. 拷贝kubeconfig文件到家目录的.kube目录

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

5. 安装网络插件

kubectl apply -f https://docs.projectcalico.org/v3.8/manifests/calico.yaml

6. 查看kube-system命名空间下的pod状态

kubectl get pod -n kube-system

7. 查看加入节点命令

cat /etc/kube-server-key | tail -2

export KUBECONFIG=/etc/kubernetes/kubelet.conf
kubectl get nodes

apt-get install bash-completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc
source  ~/.bashrc

https://blog.csdn.net/qq_44895681/article/details/107414231

https://www.cnblogs.com/xiao987334176/p/11317844.html

https://blog.csdn.net/bigboygo/article/details/77119334

https://blog.csdn.net/woshiheweigui/article/details/109200180

https://github.com/youngdou/notes/issues/19