欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Centos7 一步一步搭建K8S环境

程序员文章站 2022-03-01 13:01:20
...

Centos7 一步一步搭建K8S环境

前提条件

Centos7 安装
百度网盘链接:https://pan.baidu.com/s/1vERNTMEC37ZgKAEcYUgvKA 提取码:7cpp

基于NAT网络,配置IP

主机名 操作系统版本 docker version kubelet version flannel version
k8s_master Centos 7 18.09.6 V1.14.2 V0.11.0
k8s_node01 Centos 7 18.09.6 V1.14.2 V0.11.0
k8s_node02 Centos 7 18.09.6 V1.14.2 V0.11.0

初始化

# yum update -y
# yum install -y pip curl git zsh wget
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

安装docker

# yum install -y yum-utils   device-mapper-persistent-data   lvm2
# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum install -y docker-ce-18.09.6 docker-ce-cli-18.09.6 containerd.io
# mkdir -p /etc/docker
# tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
# systemctl daemon-reload
# systemctl restart docker

K8S 安装准备

环境准备

# systemctl stop firewalld.service
# systemctl disable firewalld.service 
# swapoff -a
# sed -i.bak '/swap/s/^/#/' /etc/fstab
# sysctl net.bridge.bridge-nf-call-iptables=1
# sysctl net.bridge.bridge-nf-call-ip6tables=1
# cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
# sysctl -p /etc/sysctl.d/k8s.conf
# 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
EOF
# yum clean all
# yum -y makecache
# yum install -y kubelet-1.14.2 kubeadm-1.14.2 kubectl-1.14.2
# systemctl enable kubelet && systemctl start kubelet

镜像准备

K8S相关镜像:https://pan.baidu.com/s/1dnZyL6AZda1CAJof341Jgg
提取码:i4qn

# docker load -i coredns_1.3.1.tar
# docker load -i etcd_3.3.10.tar
# docker load -i flannel_v0.11.0-amd64.tar
# docker load -i kube-apiserver_v1.14.2.tar
# docker load -i kube-controller-manager_v1.14.2.tar
# docker load -i kube-proxy_v1.14.2.tar
# docker load -i kubernetes-dashboard-amd64_1.10.0.tar
# docker load -i kube-scheduler_v1.14.2.tar
# docker load -i pause_3.1.tar

K8S master 安装

前提: 通过Vmware 完成克隆虚拟机 k8s-master

# cat >> /etc/hosts << EOF
192.168.137.100    k8s-master
192.168.137.101    k8s-node01
192.168.137.102    k8s-node02
EOF
# hostnamectl set-hostname k8s-master
# echo 'FORWARD_IPV4=YES' >> /etc/sysconfig/network
# echo "1" > /proc/sys/net/ipv4/ip_forward
# kubeadm init --apiserver-advertise-address 192.168.137.100 --pod-network-cidr=192.168.0.0/16
# mkdir -p $HOME/.kube
# cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# chown $(id -u):$(id -g) $HOME/.kube/config
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

K8S node01 安装

前提: 通过Vmware 完成克隆虚拟机 k8s-node01

# cat >> /etc/hosts << EOF
192.168.137.100    k8s-master
192.168.137.101    k8s-node01
192.168.137.102    k8s-node02
EOF
# hostnamectl set-hostname k8s-node01
# echo 'FORWARD_IPV4=YES' >> /etc/sysconfig/network
# echo "1" > /proc/sys/net/ipv4/ip_forward
# kubeadm join 192.168.137.100:6443 --token tiowt5.3duz1b0hwmxcz4tz \
    --discovery-token-ca-cert-hash sha256:9f1cc4746ede82e697a8fc4711feba9fcc3c4ecd323d14da220b1834cd7dfa89

K8S node02 安装

前提: 通过Vmware 完成克隆虚拟机 k8s-node02

# cat >> /etc/hosts << EOF
192.168.137.100    k8s-master
192.168.137.101    k8s-node01
192.168.137.102    k8s-node02
EOF
# hostnamectl set-hostname k8s-node02
# echo 'FORWARD_IPV4=YES' >> /etc/sysconfig/network
# echo "1" > /proc/sys/net/ipv4/ip_forward
# kubeadm join 192.168.137.100:6443 --token tiowt5.3duz1b0hwmxcz4tz \
    --discovery-token-ca-cert-hash sha256:9f1cc4746ede82e697a8fc4711feba9fcc3c4ecd323d14da220b1834cd7dfa89
相关标签: K8S Docker