一. 装centos7及初始化
- 装centos7虚拟机,内存2
https://blog.csdn.net/tsundere_x/article/details/104263100
- 设置静态ip
https://blog.csdn.net/qq_43473473/article/details/103115877?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.138.132
NETMASK=255.255.255.0
GATEWAY=192.168.138.2
DNS1=192.168.138.2
$ service network restart
- 免密登录
# vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
PasswordAuthentication yes
# master免密登录worker
$ ssh-keygen -t rsa
$ ssh-copy-id -i ~/.ssh/id_rsa.pub test@192.168.43.131
二. 装k8s master
- 修改hostname
$ hostnamectl set-hostname k8s-2
$ systemctl restart network
- vim /etc/hosts添加信息
# vim /etc/hosts
192.168.138.131 k8s-1
192.168.138.132 k8s-2
3.关闭防火枪,并设置开机关闭;关闭selinux
$ systemctl stop firewalld
$ systemctl disable firewalld
$ sed -ie 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
$ setenforce 0
- 开启系统内核转发模块 (比如 ip_forward, bridge)
# vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
$ sysctl -p
- 关闭swap,永久关闭swap
swapoff -a
# vim /etc/fstab
把swap那行注释掉
- 安装docker-ce
# step 1: 安装必要的一些系统工具
$ sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加软件源信息 (/etc/yum.repo.d)
$ sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3: 更新并安装Docker-CE
$ sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 开启Docker服务
$ sudo service docker start
# 添加阿里云加速源
# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://ubggm2kc.mirror.aliyuncs.com"]
}
$ systemctl daemon-reload
$ systemctl restart docker
$ systemctl enable docker
- 添加源 google-kubernetes.repo
# vim /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
8.安装kubeadm kubectl kubelet
$ yum -y install kubeadm-1.17.0 kubectl-1.17.0 kubelet-1.17.0
$ systemctl restart network
$ systemctl enable kubelet
$ systemctl restart kubelet
//启动网络服务
$ cat /proc/sys/net/bridge/bridge-nf-call-iptables
$ cat /proc/sys/net/bridge/bridge-nf-call-ip6tables
9.解压镜像9个(1-9 master和worker节点操作都一样)
$ kubeadm config images list --kubernetes-version=v1.17.0
$ docker load -i kube--controller-manager.tar
10.kubeadm安装k8s,设置pod/service虚拟ip范围(kubeadm初始化,仅主节点)
kubeadm init --pod-network-cidr=10.244.0.0/17 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap --kubernetes-version=v1.17.0
安装成功返回下面字段
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
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.138.131:6443 --token 96r2uy.d3i3ir4iekbn4ndl \
--discovery-token-ca-cert-hash sha256:fa8bd43d7aba4998b0930c8c0f59207e1346a87d91c763b2f25b775df03127dd
join 192.168.138.131:6443 --token 3cueu8.ctr9ta2ltcvrhruk --discovery-token-ca-cert-hash sha256:fa8bd43d7aba4998b0930c8c0f59207e1346a87d91c763b2f25b775df03127dd
# 执行下面命令
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ kubectl apply -f kube-flannel.yaml
(在1.17.0文件里)
(或者https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml)
- worker节点加如kubernetes集群
$ join 192.168.138.131:6443 --token 3cueu8.ctr9ta2ltcvrhruk --discovery-token-ca-cert-hash sha256:fa8bd43d7aba4998b0930c8c0f59207e1346a87d91c763b2f25b775df03127dd