kubernetes安装

一.环境介绍

服务器是 Linux CentOS7.9

二.kubeadm安装方式

#1.安装docker

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

sudo yum install docker-ce -y

cat < /etc/fstab


yum install -y nfs-utils
yum install -y wget


#3.配置yum源 阿里的
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

#4.安装kubelet kubeadm kubectl
yum install -y kubelet kubeadm kubectl
crictl config runtime-endpoint unix:///var/run/containerd/containerd.sock
systemctl daemon-reload
systemctl enable kubelet && systemctl start kubelet
containerd --version
kubelet --version

sed -i 's/\"cri\"//g' /etc/containerd/config.toml

systemctl restart containerd

#5.生成一个默认的kubeadm.yaml文件
kubeadm config print init-defaults >init.default.yaml

#下面是kubeadm的样例,用的把echo去掉
echo "
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 192.168.3.162
  bindPort: 6443
nodeRegistration:
  criSocket: unix:///var/run/containerd/containerd.sock
  imagePullPolicy: IfNotPresent
  name: node
  taints: null
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns:
  imageRepository: coredns
  imageTag: 1.8.6
etcd:
  local:
imageRepository: kubesphere
kind: ClusterConfiguration
kubernetesVersion: 1.28.0
networking:
  dnsDomain: cluster.local
  serviceSubnet: 10.96.0.0/12
  podSubnet: 172.16.0.0/16
scheduler: {}
---
kind: KubeletConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
cgroupDriver: systemd
" >kubeadm-config.yaml

#需要注意的参数有
podSubet: 172.16.0.0/16
advertiseAddress: 192.168.3.162
cgroupDriver: systemd
imageRepository: kubesphere

#6.先下载镜像
kubeadm config images pull --config=kubeadm-config.yaml

#7.继续下载镜像,并修改tag
ctr -n k8s.io i pull registry.aliyuncs.com/google_containers/pause:3.6
ctr -n k8s.io i tag registry.aliyuncs.com/google_containers/pause:3.6 k8s.gcr.io/pause:3.6
ctr -n k8s.io i tag registry.aliyuncs.com/google_containers/pause:3.6 registry.k8s.io/pause:3.6

#8.执行初始化
kubeadm init --config=kubeadm-config.yaml --upload-certs

#查看kubelet的日志journalctl -xeu kubelet

rm -rf /root/.kube/
mkdir /root/.kube/
cp -i /etc/kubernetes/admin.conf /root/.kube/config


#9.安装calico网络插件,因为我装的是k8s1.28,所以calico装的也是比较高的版本
kubectl apply -f https://docs.tigera.io/archive/v3.25/manifests/calico.yaml


#10. 查看运行状态
kubectl get pods -A
kubectl get pods -A -o wide

#都是running状态,就说明运行成功啦



三、安装完成后,添加node-worker类型的节点

#1.安装docker

sudo yum install -y yum-utils device-mapper-persistent-data lvm2
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce -y
cat < /etc/fstab
yum install -y nfs-utils
yum install -y wget
#3.配置yum源 阿里的
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
#4.安装kubelet kubeadm
yum install -y kubelet kubeadm
crictl config runtime-endpoint unix:///var/run/containerd/containerd.sock
systemctl daemon-reload
systemctl enable kubelet && systemctl start kubelet
containerd --version
kubelet --version

sed -i 's/\"cri\"//g' /etc/containerd/config.toml

systemctl restart containerd


#获取node加入的命令
kubeadm token create --print-join-command


#拿到上面的输出命令,在node节点上执行

四、添加node-master类型的节点

#1.安装docker

sudo yum install -y yum-utils device-mapper-persistent-data lvm2

sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

sudo yum install docker-ce -y

cat < /etc/fstab


yum install -y nfs-utils
yum install -y wget


#3.配置yum源 阿里的
cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

#4.安装kubelet kubeadm kubectl
yum install -y kubelet kubeadm kubectl
crictl config runtime-endpoint unix:///var/run/containerd/containerd.sock
systemctl daemon-reload
systemctl enable kubelet && systemctl start kubelet
containerd --version
kubelet --version

sed -i 's/\"cri\"//g' /etc/containerd/config.toml

systemctl restart containerd

ctr -n k8s.io i pull registry.aliyuncs.com/google_containers/pause:3.6
ctr -n k8s.io i tag registry.aliyuncs.com/google_containers/pause:3.6 k8s.gcr.io/pause:3.6
ctr -n k8s.io i tag registry.aliyuncs.com/google_containers/pause:3.6 registry.k8s.io/pause:3.6


#在现有的master节点上 执行命令
kubeadm init phase upload-certs --upload-certs

kubeadm token create --print-join-command

#把上面2个 节点按照下面的样式进行拼接,然后在新的node节点上 执行
kubeadm join 192.168.3.209:6443 --token 92s26s.rczw7zbohw0hkxsk --discovery-token-ca-cert-hash sha256:9775061626be21f33b2a6c90f536290e9af16c932aed2ee1674b685c7e3ffde5 --control-plane --certificate-key 8650beafcf7924973b37e980f25fcab818412868b0105140b197a629a3e31d18

你可能感兴趣的:(kubernetes,容器,云原生)