1.目的背景   


        为了学习研究grafana beyla的采集,根据官方文档要求内核至少升级至5.8以上并开启BTF重新编译,5.14以上内核版本默认开启BTF

        一开始选择了两台centos云服务器做集群部署,但是遇到了内核的各种问题,于是选择ubuntu系统重新开始。顺便记录一下k8s一主一从集群的部署搭建。(具体问题在其他帖子中会详细记录,本帖主要以最简单粗暴的方式记录k8s一主一从集群的部署)

2.环境准备

同样的内核版本ubuntu的系统确实是默认支持BTF的

主机信息

Ubuntu 22.04.2  内核版本  默认:5.15.0-76-generic   2C 2G
Ubuntu 22.04.2  内核版本  默认:5.15.0-76-generic   1C 2G


3.docker安装

摘自官方文档:Install Docker Engine on Ubuntu | Docker Docs

#添加Docker的官方GPG密钥

sudo apt-get update

sudo apt-get install ca-certificates curl

sudo install -m 0755 -d /etc/apt/keyrings

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

sudo chmod a+r /etc/apt/keyrings/docker.asc

#将存储库添加到Apt源

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt-get update

#安装 Docker 软件包

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

现在已经成功安装并启动了 Docker Engine

4.Kubernetes安装

#禁用 Swap

永久性禁用:sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

立即禁用:sudo swapoff -a

 #配置模块以支持Kubernetes(k8s)运行所需的网络功能

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay

sudo modprobe br_netfilter

#确保Linux系统具有正确的网络桥接和包转发设置,以便能够有效地支持网络模型功能。

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

sudo sysctl --system

#开始安装

sudo apt-get update

sudo apt-get install -y apt-transport-https ca-certificates curl

sudo curl --insecure -fsSLo https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 

sudo cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF

sudo apt-get update

sudo apt-get install -y kubelet kubeadm kubectl

sudo apt-mark hold kubelet kubeadm kubectl

#Containerd配置调整,确保它与Systemd的cgroup兼容

containerd config default | sudo tee /etc/containerd/config.toml >/dev/null 2>&1

sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml

#修改远程地址

sudo vim /etc/containerd/config.toml

修改 sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"

#重启生效

sudo systemctl restart containerd

#初始化(主节点执行)

sudo kubeadm init 
--apiserver-advertise-address 192.168.13.51 
--pod-network-cidr 10.244.0.0/16 
--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

启用Kubernetes命令行工具(kubectl)的自动补全功能

echo 'source <(kubectl completion bash)' >> ~/.bashrc

source ~/.bashrc

 

#安装 Flannel(主节点执行)

kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

 

#从节点加入(从节点执行)

在初始化master节点成功后会在终端输出的命令中出现这样一段命令

sudo kubeadm join 192.168.13.51:6443 
--token **************** \
--discovery-token-ca-cert-hash sha256:*********************

看到This node has joined the cluster就说明成了 

#查看集群信息

kubectl get nodes

需要等几分钟之后再执行,都是ready就完事了

5.dashboard安装

#拉取yaml

wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.0/aio/deploy/recommended.yaml

#修改service 

vi recommended.yaml 

改成这样的

kind: Service
apiVersion: v1
metadata:
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  ports:
    - protocol: TCP
      port: 443
      targetPort: 8443
      nodePort: 31350
  selector:
    k8s-app: kubernetes-dashboard
  type: NodePort

#安装 kubernetes-dashboard

kubectl apply -f recommended.yaml

#测试访问(https)

#生成token

kubectl -n kubernetes-dashboard create token admin-user

  照着命令输就完事了,遇到问题就查一查,逢山开路遇水搭桥。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐