第一個 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 重啟網(wǎng)絡

systemctl restart network

4 關閉swap

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

5 修改/etc/hosts

cat <<EOF > /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 <<EOF

disabled_plugins = ["restart"]

[plugins.linux]

shim_debug = true

[plugins.cri.registry.mirrors."docker.io"]

endpoint = ["https://frz7i079.mirror.aliyuncs.com"]

[plugins.cri]

sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.2"

EOF

8 containerd 設置為開機自動啟動并啟動

systemctl enable containerd 
systemctl start containerd

9 修改參數(shù)

修改內存參數(shù)及加載模塊

cat > /etc/modules-load.d/containerd.conf <<EOF
overlay
br_netfilter
EOF

cat  > /etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF


modprobe overlay
modprobe br_netfilter

sysctl -p /etc/sysctl.d/k8s.conf

10設置yum源

cat > /etc/yum.repos.d/kubernetes.repo <<EOF 
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

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 <<EOF
kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kubernetes-dashboard
spec:
  type: NodePort
  ports:
    - port: 443
      targetPort: 8443
  selector:
    k8s-app: kubernetes-dashboard
EOF

kubectl apply -f dashbord-svc.yml 
#查看創(chuàng)建情況
kubectl get pods --all-namespaces

kubectl get svc --all-namespaces


cat > 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}'
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容