本次在虚拟机中执行操作
首先第一步:
准备好三台节点,设置好静态ip地址,记住三台ip地址,我这边演示的ip地址分别为:
192.168.125.101 master
192.168.125.102 node1
192.168.125.103 node2
其中三台名字命名方式为:
hostnamectl set-hostname master #此命令在master节点中执行,两台node机器同理
$ systemctl stop firewalld
$ systemctl disable firewalld
$ sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
$ setenforce 0 # 临时
$ swapoff -a # 临时
$ vim /etc/fstab # 永久
$ cat >> /etc/hosts << EOF
192.168.125.101 master
192.168.125.102 node1
192.168.125.103 node2
EOF
$ sysctl --system # 生效
$ yum install ntpdate -y
$ ntpdate time.windows.com
$ yum install wget
$ wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O
/etc/yum.repos.d/docker-ce.repo
$ yum -y install docker-ce-18.06.1.ce-3.el7
$ systemctl enable docker && systemctl start docker
$ docker --version
# cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
$ cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
(这边如果不安装指定版本的会和下面的拉取安装产生冲突,版本不一致,这里一定安装指定版本)
$ yum install -y kubelet-1.17.0 kubeadm-1.17.0 kubectl-1.17.0
$ systemctl enable kubelet
$ kubeadm init \
--apiserver-advertise-address=192.168.125.101 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.17.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
此步运算完之后会出现这样的运行结果--------------------------------------------------
To start using your cluster, you need to run the following as a regular user:
(下面这三行在master运行
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:
(下面这2行在后面在node节点运行)
kubeadm join 192.168.125.101:6443 --token ag45ch.vb3bogd994laxhx6 \
--discovery-token-ca-cert-hash sha256:8e221dbd61f7bf4c8498387883d490f3dc00487df88f7d99e52e0ca481760f8a
-------------------------------------------------------------------------------------
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubeadm join 192.168.125.101:6443 --token ag45ch.vb3bogd994laxhx6 \
--discovery-token-ca-cert-hash sha256:8e221dbd61f7bf4c8498387883d490f3dc00487df88f7d99e52e0ca481760f8a
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kubeflannel.yml
第二种
[root@master ~]# wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
root@master ~]# sed -i 's/quay.io/quay-mirror.qiniu.com/g' kube-flannel.yml
[root@master ~]# kubectl apply -f kube-flannel.yml
拉取完之后执行,kubectl get nodes,就会显示全部就绪状态
$ kubectl create deployment nginx --image=nginx
$ kubectl expose deployment nginx --port=80 --type=NodePort
$ kubectl get pod,svc
接着去网站输入暴露的地址,就完成啦
如果有用请多多点赞收藏,谢谢