cento7.6安装kubernetes1.14.1
更新:HHH   时间:2023-1-7


1 .准备:两台虚拟机maste.lab.example.com 192.168.125.142 2cpu 2G 60G
node.lab.example.com 192.168.125.141 2cpu 4G 60G

  1. 更新软件包及源
    更新软件包 yum update -y
    新增源 :cd /etc/yum.repos.d
    mv CentOS-Base.repo CentOS-Base.repo.bak
    curl -o CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    sed -i 's/gpgcheck=1/gpgcheck=0/g' /etc/yum.repos.d/CentOS-Base.repo
    curl -o docker-ce.repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
    cat <<EOF > /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
    yum clean all && yum makecache
  2. 系统设置
    关闭selinux和firewalld
    setenforce 0
    sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
    systemctl stop firewalld && systemctl disable firewalld
    修改内核参数
    cat <<EOF > /etc/sysctl.d/k8s.conf
    net.bridge.bridge-nf-call-ip6tables = 1
    net.bridge.bridge-nf-call-iptables = 1
    EOF

sysctl -p
加载内核模块
modprobe br_netfilter
lsmod | grep br_netfilter
禁用swap
swapoff -a
echo "vm.swappiness = 0">> /etc/sysctl.conf
sysctl -p

  1. 安装docker
    yum install docker-ce
    设置镜像加速器(这里我使用了自己个人的阿里云镜像加速,根据个人实际情况来写)
    mkdir -p /etc/docker
    tee /etc/docker/daemon.json <<-'EOF'
    {
    "registry-mirrors": ["https://o9ofxrn0.mirror.aliyuncs.com"]
    }
    EOF
    systemctl daemon-reload
    systemctl restart docker && systemctl enable docker
    1. 加载镜像
      由于国内网络已被墙,我在这里事先吧1.14.1的镜像提供出来
      链接:https://pan.baidu.com/s/1QkRoRHLFJxrQHAuslpFN4Q
      提取码:ovgt
      复制这段内容后打开百度网盘手机App,操作更方便哦
    2. 安装kubeadm、kubelet和kubectl
      yum install -y kubelet kubeadm kubectl
      注:我这里现在yum源中是1.14.1的版本,之后会有更新的版本,如果是更高或者是其他版本,我这里提供的镜像就不能用了。
      kubeadm init --pod-network-cidr=10.244.0.0/16
      跑完上面的init命令后会看到类似如下的输出:
      Your Kubernetes master 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

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/

You can now join any number of machines by running the following on each node
as root:
kubeadm join 192.168.125.142:6443 --token 5fasbl.ctmnsuq04udlb8t2 \
--discovery-token-ca-cert-hash sha256:c7fea93fa4ebcc695a48720fb007185102167bbd7f7ff9d2be178efdee20dad0
接下来你懂的,该怎么做!!!

返回云计算教程...