win7环境虚拟机在线搭建k8s环境
win7环境虚拟机在线搭建k8s环境一.环境介绍一共三台CentOS Linux release 7.6.1810 (Core)192.168. 2.130 master192.168. 2.119 node1192.168. 2.156 node2本机网络配置:VMware配置:虚拟机地址设置参考:vi /etc/sysconfig/network-scripts/ifcfg-ens33TYPE
win7环境虚拟机在线搭建k8s环境
一.环境介绍
一共三台
CentOS Linux release 7.6.1810 (Core)
192.168. 2.130 master
192.168. 2.119 node1
192.168. 2.156 node2
本机网络配置:
VMware配置:
虚拟机地址设置参考:
vi /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.2.130
NETMASK=255.255.255.0
GATEWAY=192.168.2.2
DNS2=114.114.114.114
DNS3=8.8.8.8
保证虚拟机与外网畅通
ping www,baidu.com 正常
二.三台虚机安装docker
1. yum install docker
docker启动 命令:
systemctl start docker
systemctl enable docker
验证docker 安装情况:
[root@k8s-master istio]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-203.git0be3e21.el7.centos.x86_64
Go version: go1.10.3
Git commit: 0be3e21/1.13.1
Built: Thu Nov 12 15:11:46 2020
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-203.git0be3e21.el7.centos.x86_64
Go version: go1.10.3
Git commit: 0be3e21/1.13.1
Built: Thu Nov 12 15:11:46 2020
OS/Arch: linux/amd64
Experimental: false
三、前提准备
三台机器都做如下操作
关闭防火墙
systemctl disable firewalld.service
systemctl stop firewalld.service
setenforce 0
开启centos的bridge-nf:
编辑文件vi /etc/sysctl.conf 添加:
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
sysctl -p 使上面的配置生效。
关闭SELinux
vi /etc/selinux/config
SELINUX=disabled
source /etc/selinux/config
禁用交换内存
swapoff -a
vi /etc/fstab
找到有swap的那行,注释掉
yum update
yum install update
四.安装kubectl、kubelet、kubeadm
添加阿里kubernetes源
[root@master01 ~]# 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
安装
[root@master01 ~]# yum install kubectl kubelet kubeadm
[root@master01 ~]# systemctl enable kubelet && systemctl start kubelet
systemctl enable kubelet && systemctl start kubelet
确保上面三个组件都安装成功
五 初始化k8s集群
[root@master01 ~]# kubeadm init --kubernetes-version=1.19.0 \
--apiserver-advertise-address=192.168.2.130 \
--image-repository registry.aliyuncs.com/google_containers \
--service-cidr=10.10.0.0/16 --pod-network-cidr=10.122.0.0/16
kubeadm init --apiserver-advertise-address 192.168.2.130 \
--pod-network-cidr 10.244.0.0/16 \
--image-repository=registry.aliyuncs.com/google_containers
记录token供NODE节点加入集群使用
六 .NODE节点加入集群
kubeadm join 192.168.2.130:6443 --token mpxd78.zq5cx4oae9rg9eod \
--discovery-token-ca-cert-hash sha256:3bc63d32d80fefc6df60bde78f4165321a65c8a719767afb4f18db685b72cc7e
替换成自己的token
1、获取token值:kubeadm token list
2、重新生成token和hash参数值:kubeadm token create --print-join-command
配置 kubectl
echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> /etc/profile
source /etc/profile
echo $KUBECONFIG
[root@k8s-master yum.repos.d]# kubectl get node
NAME STATUS ROLES AGE VERSION
k8s-master NotReady master 15m v1.19.1
node节点为NotReady,因为corednspod没有启动,缺少网络pod
七.安装calico网络
[root@master01 ~]# kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
至此安装完毕:
[root@k8s-master ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
k8s-master Ready master 145d v1.19.1
k8s-node1 Ready <none> 144d v1.19.1
k8s-node2 Ready <none> 144d v1.19.1
在master上查看节点状态,如果存在NotReady的节点:
假如node1节点状态为NotReady,可参考下面方法设置:
删除node1所有运行的容器,node1
docker stop $(docker ps -q) & docker rm $(docker ps -aq)
重置 kubeadm ,node1
kubeadm reset
获取join指令,master
kubeadm token create --print-join-command
再次在node1上运行join
kubeadm join 192.168.2.130:6443 --token jmojrm.2li4fae4os9nnrud --discovery-token-ca-cert-hash sha256:3bc63d32d80fefc6df60bde78f4165321a65c8a719767afb4f18db685b72cc7e
更多推荐
所有评论(0)