ubuntu 20.04 安装k8s指南
ubuntu, kubuneters
基础环境检查
############################################################
1,设置主机名 hostnamectl
hostnamectl set-hostname xxxx
主机名加入/etc/hosts
2,配置系统网络
root@k1:~#cd /etc/netplan/
root@k1:~# vi /etc/netplan/00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
ethernets:
ens18:
addresses: [172.17.50.28/24]
gateway4: 172.17.50.254
nameservers:
addresses: [114.114.114.114]
dhcp4: no
version: 2
root@k1:~# netplay apply
注:dns修改/etc/resolv.conf 会被覆盖,dns设置在netplan文件中
3, 系统时间确认
timedatectl set-timezone Asia/Shanghai
4, 关闭swap
root@k2:~# swapoff -a
root@k2:~# vi /etc/fstab
注释掉swap 那行
5,更新apt 国内源
1)
sudo tee /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
EOF
2)
# curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
# tee /etc/apt/sources.list.d/kubernetes.list <<EOF
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
6, apt-get update
#############################################################
软件安装
1,apt-get update
2, 安装 docker
apt-get install docker.io -y
3, 安装k8s组件
apt-get install -y kubelet=1.23.6-00 kubeadm=1.23.6 kubectl=1.23.6
4, 阻止自动更新
apt-mark hold kubeadm kubelet kubectl
5, 修改docker 镜像源地址
#docker info 查看当前镜像地址
vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"live-restore": true,
"exec-opts": ["native.cgroupdriver=systemd"]
}
6, 初始化集群控制节点
原始初始化命令:kubeadm init --apiserver-advertise-address $(hostname -i)
原始初始化命令会因为无法拉取镜像而报错,修改阿里云地址:
kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --kubernetes-version=v1.24.2
kubelet无法启动报错,修改docker driver为systemd
kubelet is not properly working on 1.22 version - k8shttps://sysnet4admin.gitbook.io/k8s/trouble-shooting/cluster-build/kubelet-is-not-properly-working-on-1.22-version#1.error-during-kubeadm-init7, 集群创建成功的日志
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Alternatively, if you are the root user, you can run:
export KUBECONFIG=/etc/kubernetes/admin.conf
You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/
Then you can join any number of worker nodes by running the following on each as root:
kubeadm join 172.17.50.29:6443 --token ma9niu.dr7wavctoym5oiiz \
--discovery-token-ca-cert-hash sha256:7b0f1824ea07ed6de7a2fb07b9dabfe040e03b8296fc9e76330c3e2eaf4c0de6
8,检查集群状态:
首先输出环境变量:
export KUBECONFIG=/etc/kubernetes/admin.conf
查看节点状态:
root@k1:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k1 NotReady control-plane,master 49m v1.23.2
解决节点 not ready 问题
https://www.containiq.com/post/debugging-kubernetes-nodes-in-not-ready-state
9,安装集群网络插件:
网络插件导读:
https://www.skynemo.cn/archives/01-k8s-install-with-kubeadm
kubectl apply -n kube-system -f \
"https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 |tr -d '\n')"
10,查看节点状态:
root@k1:/etc/docker# kubectl get node
NAME STATUS ROLES AGE VERSION
k1 Ready control-plane,master 19h v1.23.2
k2 Ready <none> 16h v1.23.3
k3 Ready <none> 83m v1.23.3
更多推荐
所有评论(0)