Local Desktop: MacOS
Virtual Machine: vmware fusion
Virtual System: CentOS 7.2
Kubernetes: Kubernetes1.9
Docker: 1.13.1
主机名 | IP |
---|---|
master | 192.168.48.131 |
node1 | 192.168.48.129 |
node2 | 192.168.48.130 |
node3 | 192.168.48.128 |
(Master Node都需要配置)
链接:https://pan.baidu.com/s/1kjhCqh5DlcBHkqRyHOx8oQ 密码:9dma
下载到本地后, 上传到虚拟机root根目录
# bzip2 -d k8s_images.tar.bz2
# tar xvf k8s_images.tar
# yum install policycoreutils-python libtool-ltdl libseccomp device-mapper-libs kernel ntpdate
# reboot
# echo "192.168.48.131 matser" >> /etc/hosts
# echo "192.168.48.129 node1" >> /etc/hosts
# echo "192.168.48.130 node2" >> /etc/hosts
# echo "192.168.48.128 node3" >> /etc/hosts
注:这里可在配置秘钥之后 scp /etc/hosts 到各个node上,不需要挨个配置
# ssh-keygen
# ssh-copy-id node1
# ssh-copy-id node2
# ssh-copy-id node3
# vi /etc/sysconfig/selinux
...
SELINUX=disabled
...
# systemctl stop firewalld && systemctl disable firewalld
# reboot (修改完 selinux 需要重启生效)
# modprobe br_netfilter
# echo "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.conf
# echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf
# sysctl -p
大家在安装CentOS7时如果配置了swap分区, 这里由于k8s禁止系统开启此功能, 需要提前进行关闭, 没有配置swap请无视.
查看swap分区
free -m (已关闭状态)
# free -m
total used free shared buff/cache available
Mem: 974 488 70 14 415 294
Swap: 0 0 0
# swapoff -a (关闭swap分区)
注释掉swap分区, 禁止开机启动swap
# vi /etc/fstab
...
#/dev/mapper/centos-swap swap swap defaults 0 0
...
# systemctl enable ntpdate && systemctl start ntpdate
(Master Node都需要配置)
# yum -y install docker
# vi /etc/docker/daemon.json
...
{
"registry-mirrors": ["https://mirror.ccs.tencentyun.com"]
}
...
# systemctl daemon-reload
# systemctl restart docker
# systemctl enable docker
# cd /root
# vi image.sh
docker load < /root/k8s_images/docker_images/etcd-amd64_v3.1.10.tar
docker load </root/k8s_images/docker_images/flannel:v0.9.1-amd64.tar
docker load</root/k8s_images/docker_images/k8s-dns-dnsmasq-nanny-amd64_v1.14.7.tar
docker load </root/k8s_images/docker_images/k8s-dns-kube-dns-amd64_1.14.7.tar
docker load </root/k8s_images/docker_images/k8s-dns-sidecar-amd64_1.14.7.tar
docker load </root/k8s_images/docker_images/kube-apiserver-amd64_v1.9.0.tar
docker load </root/k8s_images/docker_images/kube-controller-manager-amd64_v1.9.0.tar
docker load </root/k8s_images/docker_images/kube-scheduler-amd64_v1.9.0.tar
docker load < /root/k8s_images/docker_images/kube-proxy-amd64_v1.9.0.tar
docker load </root/k8s_images/docker_images/pause-amd64_3.0.tar
docker load < /root/k8s_images/kubernetes-dashboard_v1.8.1.tar
#chmod +x image.sh
# sh image.sh
# cd k8s_images
# rpm -ivh socat-1.7.3.2-2.el7.x86_64.rpm kubernetes-cni-0.6.0-0.x86_64.rpm kubelet-1.9.9-9.x86_64.rpm kubectl-1.9.0-0.x86_64.rpm kubeadm-1.9.0-0.x86_64.rpm
# systemctl enable kubelet && sudo systemctl start kubelet
# docker info |grep "Cgroup Driver"
如果"Cgroup Driver"value为 "cgroupfs", 将其值写入kubeadm配置文件
# vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
...
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver="cgroupfs"
...
我实验中Cgroup Driver参数默认是 systemd,跟配置文件中的保持一致,无需修改。
# systemctl daemon-reload && systemctl restart kubelet
# kubeadm reset
# kubeadm init --kubernetes-version=v1.9.0 --pod-network-cidr=10.244.0.0/16
Tip: 这里的10.244.0.0/16与默认的配置文件网段一致, 如需调整请在后面的kube-flannel.yml文件做相应改变
如果一切没问题会output一个token返回命令
# kubeadm join --token 288f34.481c8faa5636966f 10.110.16.10:6443 --discovery-token-ca-cert-hash sha256:8036fac3b76e1a0dd189edaa8f7d36f2b51429dd0c0cf7ea0d78e7972d611002
如果初始化时卡在某一步不能继续下去的时候,可以通过 journalctl -xeu kubelet 查看初始化日志,找到错误原因。
注意:如果之前初始化过集群,但是没成功,后续尝试先kubeadm reset 然后再执行 kubeadm init 操作
24小时后这个token会失效, 需要重新生成, 使用如下命令进行生成.
# kubeadm token create
# kubeadm join --token "Your token code" "Your master ip address":6443
如果在24小时内忘记了,可以用如下命令获取.
# kubeadm token list
好了初始化 Master 完成后,我们使用命令 kubectl get node 查看集群节点信息,但是你会发现并没有出现 Node 信息,反而报错如下:
$ kubectl get node
The connection to the server localhost:8080 was refused - did you specify the right host or port?
What?上边不都显示安装完成了吗?其实是已经初始化完成了,只不过想使用集群的话,少了上边日志输出的那一步。
如果你使用的是root
# echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
# source ~/.bash_profile
如果是非root用户
# mkdir -p $HOME/.kube
# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
# sudo chown $(id -u):$(id -g) $HOME/.kube/config
测试kubectl版本
# kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T21:07:38Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.0", GitCommit:"925c127ec6b946659ad0fd596fa959be43f0cc05", GitTreeState:"clean", BuildDate:"2017-12-15T20:55:30Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"linux/amd64"}
然后再次查看node ,发现已经可以正常显示master 和 三个node 的信息了
# kubectl get node
NAME STATUS ROLES AGE VERSION
master Ready master 1h v1.9.0
node1 NotReady <none> 1h v1.9.0
node2 NotReady <none> 1h v1.9.0
node3 NotReady <none> 1h v1.9.0
我们再使用命令kubectl get pod --all-namespaces 查看当前节点所有的 pod。
$ kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system etcd-master.localdomain 1/1 Running 0 23h
kube-system kube-apiserver-master.localdomain 1/1 Running 0 1d
kube-system kube-controller-manager-master.localdomain 1/1 Running 0 1d
kube-system kube-dns-3913472980-37b6d 0/3 Pending 0 14m
kube-system kube-proxy-czzg9 1/1 Running 0 1d
kube-system kube-scheduler-master.localdomain 1/1 Running 0 1d
这里 kube-dns 显示状态为 Pending,没有关系,这是因为还没有安装 Pod Network 组件导致的,接下来我们安装 Flannel 网络组件后,它就会自动跑起来了。
#wget https://raw.githubusercontent.com/coreos/flannel/v0.9.1/Documentation/kube-flannel.yml
Tip: 这里的yml配置文件内的网段配置需与上面介绍的Master初始化的配置网段"--pod-network-cidr=10.244.0.0/16" 一致
稍等一下我们再来查看所有pod详细信息
# kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system etcd-master 1/1 Running 2 1h
kube-system kube-apiserver-master 1/1 Running 2 1h
kube-system kube-controller-manager-master 1/1 Running 2 1h
kube-system kube-dns-6f4fd4bdf-7sgsd 3/3 Running 0 1h
kube-system kube-flannel-ds-284vj 1/1 Running 0 1h
kube-system kube-flannel-ds-5mzwr 1/1 Running 0 1h
kube-system kube-flannel-ds-fmxvd 1/1 Running 3 1h
kube-system kube-flannel-ds-wk5vv 1/1 Running 0 1h
kube-system kube-proxy-7tv6s 1/1 Running 0 1h
kube-system kube-proxy-hd659 1/1 Running 0 1h
kube-system kube-proxy-qps9m 1/1 Running 0 1h
kube-system kube-proxy-wlqjl 1/1 Running 2 1h
kube-system kube-scheduler-master 1/1 Running 2 1h
现在是不是都是 Running 状态啦!
到此,安装kubenetes 1.9.0 完美结束,至于后面安装Kubernetes Dashboard操作,网上有很多教程文档,这里不再详述。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。