本地集群k8s 1.23(非docker)

1准备三台虚拟机 (省略)

192.168.37.21 hostnamectl set-hostname k8s01
192.168.37.22 hostnamectl set-hostname k8s02
192.168.37.23 hostnamectl set-hostname k8s03

2 修改IP地址

vi /etc/sysconfig/network-script/ifcfg-enp0s3

3 重启网络

systemctl restart network

4 关闭swap

swapoff  -a
sed -i '/swap/s/^/#/' /etc/fstab

5 修改/etc/hosts

cat < /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.137.21 k8s01
192.168.137.22 k8s02
192.168.137.23 k8s03
EOF

#6 安装 containerd

yum install  -y containerd.io cri-tools  

7 修改containerd的配置文件/etc/containerd/config.toml

cat >  /etc/containerd/config.toml <

8 containerd 设置为开机自动启动并启动

systemctl enable containerd
systemctl start containerd

9 修改参数

修改内存参数及加载模块

cat > /etc/modules-load.d/containerd.conf < /etc/sysctl.d/k8s.conf <

10设置yum源

cat > /etc/yum.repos.d/kubernetes.repo <

11安装 kubelet kubeadmin kubectl

yum install -y kubelet-1.23.1-0 kubeadm-1.23.1-0 kubectl-1.23.1-0

yum -y remove kubelet-1.24.0-0 kubeadm-1.24.0-0 kubectl-1.24.0-0

12重启机器以及关闭防火墙

reboot
systemctl disable firewalld
systemctl stop firewalld
systemctl enable kubelet.service

13初始化集群

kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.23.1 --pod-network-cidr=10.244.0.0/16

14按照提示

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

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
export KUBECONFIG=/etc/kubernetes/admin.conf

15查看k8s01 node

kubectl get nodes -o wide

16将k8s02 k8s03 加入集群

kubeadm join 192.168.137.21:6443 --token t9xpdk.hp4m0g049ymcw6yo \
        --discovery-token-ca-cert-hash sha256:d2ac77f602960b2e3170a02e549381f1d32511e7a2fb5a1e2f8a89de6fecca0

17安装calico

mkdir -p /root/install/calico
cd /root/install/calico
wget https://docs.projectcalico.org/v3.16/manifests/calico.yaml --no-check-certificate
kubectl apply -f calico.yaml

18安装dashboard

mkdir -p /root/install/dashboard
cd  /root/install/dashboard
wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml
kubectl apply -f recommended.yml  

kubectl delete service kubernetes-dashboard --namespace=kubernetes-dashboard

cat >dashbord-svc.yml < dashboard-adminuser.yaml << EOF
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin-user
  namespace: kubernetes-dashboard
 
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: admin-user
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard  

EOF

kubectl get secret -n kubernetes-dashboard |grep admin|awk '{print $1}'


kubectl describe secret admin-user-token-zzhgz -nkubernetes-dashboard|grep '^token'|awk '{print $2}'

你可能感兴趣的:(docker,kubernetes,linux)