这篇文章介绍了如何快速部署一套Kubernetes集群,下面就快速开始吧!
准备工作
//关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service
//关闭selinux,修改/etc/selinux/config
SELINUX=disabled
机器部署规划
主机 | IP | 部署组件 |
---|---|---|
master主节点 | 192.168.199.206 | etcd、kube-apiserver、kube-controller-manager、kube-scheduler |
node1子节点 | 192.168.199.159 | kubelet、kube-proxy、docker |
node2子节点 | 192.168.199.175 | kubelete、kube-proxy、docker |
k8s组件采用yum安装的方式,快速安装。
Master节点
//安装etcd
[root@206 ~]# yum install -y etcd
//修改/etc/etcd/etcd.conf配置文件
[root@206 ~]# vim /etc/etcd/etcd.conf
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.199.206:2379"
//配置etcd内网信息
[root@206 ~]# etcdctl set /atomic.io/network/config '{"Network":"172.17.0.0/16"}'
ps:其中网络号172.17.0.0/16与docker中的docker0网络一致(若不一致,可修改docker0网络或者配置上述etcd网络);
atomic.io与下面的Flannel配置中的FLANNEL_ETCD_PREFIX对应;
//运行etcd服务
[root@206 ~]# systemctl start etcd
[root@206 ~]# systemctl enbale etcd
//安装kubernetes-master
[root@206 ~]# yum install -y kubernetes-master
//修改/etc/kubernetes/apiserver配置文件
[root@206 ~]# vim /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-servers=http://192.168.199.206:2379"
//修改/etc/kubernetes/config配置文件
[root@206 ~]# vim /etc/kubernetes/config
KUBE_MASTER="--master=http://192.168.199.206:8080"
//运行master服务
[root@206 ~]# systemctl start kube-apiserver kube-scheduler kube-controller-manager
[root@206 ~]# systemctl enable kube-apiserver kube-scheduler kube-controller-manager
//测试服务,若输出以下数据,则服务正常。
[root@206 ~]# curl -l http://192.168.199.206:8080
{
"paths": [
"/api",
"/api/v1",
"/apis",
"/apis/apps",
"/apis/apps/v1beta1",
"/apis/authentication.k8s.io",
"/apis/authentication.k8s.io/v1beta1",
"/apis/authorization.k8s.io",
"/apis/authorization.k8s.io/v1beta1",
"/apis/autoscaling",
"/apis/autoscaling/v1",
"/apis/batch",
"/apis/batch/v1",
"/apis/batch/v2alpha1",
"/apis/certificates.k8s.io",
"/apis/certificates.k8s.io/v1alpha1",
"/apis/extensions",
"/apis/extensions/v1beta1",
"/apis/policy",
"/apis/policy/v1beta1",
"/apis/rbac.authorization.k8s.io",
"/apis/rbac.authorization.k8s.io/v1alpha1",
"/apis/storage.k8s.io",
"/apis/storage.k8s.io/v1beta1",
"/healthz",
"/healthz/ping",
"/healthz/poststarthook/bootstrap-controller",
"/healthz/poststarthook/extensions/third-party-resources",
"/healthz/poststarthook/rbac/bootstrap-roles",
"/logs",
"/metrics",
"/swaggerapi/",
"/ui/",
"/version"
]
Node节点(159和175安装方法一样)
//安装docker
[root@159 ~]# yum install -y docker
//安装flannel
[root@159 ~]# yum install -y flannel
//修改/etc/sysconfig/flannel配置文件
[root@159 ~]# vim /etc/sysconfig/flannel
FLANNEL_ETCD_ENDPOINTS="http://192.168.199.206:2379"
//安装kubernetes-note
[root@159 ~]# yum install -y kubernetes-node
//修改/etc/kubernetes/config配置文件
[root@159 ~]# vim /etc/kubernetes/config
KUBE_MASTER="--master=http://192.168.199.206:8080"
//修改/etc/kubernetes/kubelet配置文件
[root@159 ~]# vim /etc/kubernetes/kubelet
KUBELET_HOSTNAME="--hostname-override=192.168.199.159"
KUBELET_API_SERVER="--api-servers=http://192.168.199.206:8080"
//运行服务
systemctl enable kubelet kube-proxy
systemctl start kubelet kube-proxy
在Master机器上管理Node节点
[root@206 ~]# kubectl get nodes
NAME STATUS AGE
192.168.199.159 Ready 32m
192.168.199.175 Ready 4m