集群清单
角色 | 系统配置 | IP | 系统 |
Master | 最低双核2G内存30G硬盘 | 192.168.56.130 | Ubuntu18.04 |
Node | 最低双核2G内存30G硬盘 | 192.168.56.129 | Ubuntu18.04 |
一、初始化设置(所有节点都需执行)
1、配置静态IP
- #下载网络工具
- sudo apt-get install network-manager
- # 记住网卡名称
- ifconfig
- # 记住网关地址
- netstat -rn
打开vi /etc/netplan/00-installer-config.yaml文件,进行如下配置
- network:
- renderer: NetworkManager
- ethernets:
- ens33:
- dhcp4: false
- dhcp6: false
- addresses: [192.168.56.130/24] # 本机IP/掩码
- gateway4: 192.168.56.2 # 网关
- nameservers:
- addresses: [8.8.8.8] # DNS地址,和网关一致,也能使用8.8.8.8或者144.144.144.144
- version: 2
配置完成后对其进行更新,并测试
- # 应用更改
- netplan apply
- # 测试是否成功
- ping www.baidu.com(如果不通,再执行一次netplan apply,或者更改DNS)
2、设置时区
- # 设置时区
- timedatectl set-timezone Asia/Shanghai
- # 设置校时服务
- apt-get install ntpdate
- ntpdate ntp.aliyun.com
3、关闭Selinux(Ubuntu默认没有安装,可跳过)
- setenforce 0
- sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
4、关闭swap(k8s官方不支持swap)
- swapoff -a
- sed -i 's/.*swap.*/#&/' /etc/fstab
- free -m
5、设置主机名
- cat /etc/hostname << EOF
- 192.168.56.130 master
- 192.168.56.129 node
- EOF
6、将桥接的 IPv4 流量传递到 iptables
- cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
- net.bridge.bridge-nf-call-iptables = 1
- net.bridge.bridge-nf-call-ip6tables = 1
- net.ipv4.ip_forward = 1
- EOF
- sysctl --system
7、关闭防火墙
- apt-get install iptables
- ufw disable
- sysctl --system
二、安装Container
1、下载apt仓库所需包
- # 更新apt包
- apt-get update
- # 安装
- apt-get -y install apt-transport-https ca-certificates curl software-properties-common
2、安装密钥
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
3、添加存储库
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
4、更新,安装docker-ce
- # 更新
- apt-get -y update
- # 安装docker-ce
- apt-get -y install docker-ce
6、创建配置并启动
- mkdir /etc/docker
- # Setup daemon.
- cat > /etc/docker/daemon.json <<EOF
- {
- "exec-opts": ["native.cgroupdriver=systemd"],
- "log-driver": "json-file",
- "log-opts": {
- "max-size": "100m"
- },
- "registry-mirrors": ["https://e6vlzg9v.mirror.aliyuncs.com"]
- }
- EOF
- mkdir -p /etc/systemd/system/docker.service.d
- chmod 777 /var/run/docker.sock
- sed -i '/^disabled_plugins/d' /etc/containerd/config.toml
- systemctl restart containerd
- systemctl daemon-reload && service docker start && systemctl enable docker
- docker ps
- cat <<EOF> /etc/crictl.yaml
- runtime-endpoint: unix:///run/containerd/containerd.sock
- image-endpoint: unix:///run/containerd/containerd.sock
- timeout: 10
- debug: false
- EOF
- systemctl restart containerd
- systemctl daemon-reload && service docker start && systemctl enable docke
- crictl images
三、安装Kubernetes三剑客(kubelet、kubeadm、kubectl)
1、更新包并下载apt-transport-https
apt-get update && apt-get install -y apt-transport-https
2、配置镜像源并更新
- sudo curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
- cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
- deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
- EOF
- apt-get update
3、安装指定版本的三剑客
apt-get install -y kubelet=1.24.0-00 kubeadm=1.24.0-00 kubectl=1.24.0-00
4、设置开机自,启动并查看状态
systemctl enable kubelet && systemctl start kubelet && systemctl status kubelet
四、初始化集群
由于v1.24 版本的k8s 使用的是containerd。 docker load 和 ctr images import 都无效。所以通过手动拉取镜像的方式拉取所需镜像。(每台都执行)
- crictl pull docker.io/calico/cni:v3.24.0
- crictl pull docker.io/calico/kube-controllers:v3.24.0
- crictl pull docker.io/calico/node:v3.24.0
- crictl pull docker.io/library/nginx:latest
- crictl pull registry.aliyuncs.com/google_containers/pause:3.6
- crictl pull registry.aliyuncs.com/google_containers/coredns:v1.8.6
- crictl pull registry.aliyuncs.com/google_containers/etcd:3.5.3-0
- crictl pull registry.aliyuncs.com/google_containers/kube-apiserver:v1.24.0
- crictl pull registry.aliyuncs.com/google_containers/kube-controller-manager:v1.24.0
- crictl pull registry.aliyuncs.com/google_containers/kube-proxy:v1.24.0
- crictl pull registry.aliyuncs.com/google_containers/kube-scheduler:v1.24.0
- crictl pull registry.aliyuncs.com/google_containers/pause:3.7
- ctr -n k8s.io i tag registry.aliyuncs.com/google_containers/pause:3.6 k8s.gcr.io/pause:3.6
1、配置Master节点
(1)初始化集群
sudo kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --kubernetes-version=v1.24.0 --ignore-preflight-errors=all -v5
(2)文件创建
- sudo mkdir -p $HOME/.kube
- sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
- sudo chown $(id -u):$(id -g) $HOME/.kube/config
(3)写入配置
- echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
- source /etc/profile
(4)将admin.conf拷贝到其他节点的指定目录下
scp /etc/kubernetes/admin.conf user:xxx.xxx.xxx.xxx:/etc/kubernetes/
2、配置Node节点
(1)确认admin.conf已经拷贝到指定目录,并拥有足够权限,写入配置
- ll /etc/kubernetes/admin.conf
- echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
(2)执行Master集群初始化后的命令,如果忘记可以在Master节点上执行“sudo kubeadm token create --print-join-command”命令,然后将输出复制到Node节点执行
sudo kubeadm join xxx --token xxxxx --discovery-token-ca-cert-hash sha256:xxxx -v 5
五、安装网络插件(Master上执行)
sudo curl https://docs.projectcalico.org/manifests/calico.yaml -O && kubectl apply -f calico.yaml
六、部署测试应用
1、在Master上执行kubectl get node,当Status显示为Ready时再执行下面语句,创建tomcat服务。
- kubectl create deployment tomcat --image=tomcat
- kubectl expose deployment tomcat --port=8080 --target-port=8080 --type=NodePort
2、执行“kubectl get pods”命令,当Status为Running且Ready为1/1时执行下面命令,确认端口为31423
- # 找到端口号
- root@master:~# kubectl get service
- NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
- kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 34m
- tomcat NodePort 10.108.160.28 <none> 8080:31423/TCP 30m
3、在网页输入cluster IP+service port,进行访问。出现如下页面,则集群搭建成功
源地址: (82条消息) Kubernetes 1.24 Ubuntu18.04安装_ubuntu18.04 selinux查看是否安装_梦·D·的博客-CSDN博客
标签:Kubernetes,get,apt,etc,crictl,docker,Ubuntu18.04,com,1.24 From: https://www.cnblogs.com/colin88/p/17231045.html