一、初始化


sudo yum install -y yum-utils
sudo yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i -re '/^\s*SELINUX=/s/^/#/' -e '$i\\SELINUX=disabled'  /etc/selinux/config
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab


echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf

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

二、安装docker

​​​​​​​yum install docker-ce

修改/etc/docker/daemon.json文件
{
 "registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"],
  "exec-opts": ["native.cgroupdriver=systemd"]

}

systemctl start docker.service
systemctl enable docker.service

三、安装kubeadm

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


yum install -y kubelet kubeadm kubectl
systemctl enable kubelet
systemctl start kubelet

四、初始化

kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.207.133 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap --image-repository registry.aliyuncs.com/google_containers

初始化成功返回结果

Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

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

Alternatively, if you are the root user, you can run:

  export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.207.133:6443 --token vtulbn.0awdx1n9h977qt17 \
    --discovery-token-ca-cert-hash sha256:2d849e3dccefc1c624be7670a371794ed7cad0fc0d4f11e8c7ccfe9a3b32dcfd 

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

五、安装网络插件

wget https://docs.projectcalico.org/v3.20/manifests/calico.yaml --no-check-certificate
grep image calico.yaml 
sed -i 's/docker.io/quay.io/g' calico.yaml 
grep image calico.yaml 
kubectl apply -f calico.yaml 

六、node节点加入集群

yum -y install kubelet kubeadm # node 上安装

kubeadm join 192.168.207.133:6443 --token vtulbn.0awdx1n9h977qt17 \
    --discovery-token-ca-cert-hash sha256:2d849e3dccefc1c624be7670a371794ed7cad0fc0d4f11e8c7ccfe9a3b32dcfd

七、kubectl命令补全

yum -y install bash-completion
source /usr/share/bash-completion/bash_completion

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

八、部署metrics-server

metrics-serveryaml文件-kubernetes文档类资源-CSDN下载

下载完成后kubectl apply -f metrics-server.yaml

Logo

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

更多推荐