k8s入门系列之集群安装篇
kubernetes集群组件:
- etcd 一个高可用的k/v键值对存储和服务发现系统
- flannel 实现夸主机的容器网络的通信
- kube-apiserver 提供kubernetes集群的api调用
- kube-controller-manager 确保集群服务
- kube-scheduler 调度容器,分配到node
- kubelet 在node节点上按照配置文件中定义的容器规格启动容器
- kube-proxy 提供网络代理服务
一.安装配置kubernetes master 如下操作在master上执行 1.使用yum安装etcd和kubernetes-master
# yum -y install etcd kubernetes-master
2.编辑/etc/etcd/etcd.conf文件
etcd_name=default etcd_data_dir="/var/lib/etcd/default.etcd" etcd_listen_client_urls="http://0.0.0.0:2379" etcd_advertise_client_urls="http://localhost:2379"
3.编辑/etc/kubernetes/apiserver文件
kube_api_address="--insecure-bind-address=0.0.0.0"
kube_api_port="--port=8080"
kubelet_port="--kubelet-port=10250"
kube_etcd_servers="--etcd-servers=http://127.0.0.1:2379"
kube_service_addresses="--service-cluster-ip-range=10.254.0.0/16"
kube_admission_control="--admission-control=namespacelifecycle,namespaceexists,limitranger,securitycontextdeny,resourcequota"
kube_api_args=""
4.启动etcd、kube-apiserver、kube-controller-manager、kube-scheduler等服务,并设置开机启动。
for services in etcd kube-apiserver kube-controller-manager kube-scheduler;
do
systemctl restart $services;
systemctl enable $services;
systemctl status $services ;
done
5.在etcd中定义flannel网络
etcdctl mk /atomic.io/network/config '{"network":"172.17.0.0/16"}'
二.安装配置kubernetes node
如下操作在node1、node2上执行
1.使用yum安装flannel和kubernetes-node
yum -y install flannel kubernetes-node
2.为flannel网络指定etcd服务,修改/etc/sysconfig/flanneld文件
flannel_etcd="http://192.168.1.139:2379"
flannel_etcd_key="/atomic.io/network"
3.修改/etc/kubernetes/config文件
kube_logtostderr="--logtostderr=true"
kube_log_level="--v=0"
kube_allow_priv="--allow-privileged=false"
kube_master="--master=http://192.168.1.139:8080"
4.按照如下内容修改对应node的配置文件/etc/kubernetes/kubelet
第一个节点
kubelet_address="--address=0.0.0.0"
kubelet_port="--port=10250"
kubelet_hostname="--hostname-override=192.168.1.21" #修改成对应node的ip
kubelet_api_server="--api-servers=http://192.168.1.139:8080" #指定master节点的api server
kubelet_pod_infra_container="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
kubelet_args=""
第二个节点
kubelet_address="--address=0.0.0.0"
kubelet_port="--port=10250"
kubelet_hostname="--hostname-override=192.168.1.141" #修改成对应node的ip
kubelet_api_server="--api-servers=http://192.168.1.139:8080" #指定master节点的api server
kubelet_pod_infra_container="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
kubelet_args=""
5.在所有node节点上启动kube-proxy,kubelet,docker,flanneld等服务,并设置开机启动。
for services in kube-proxy kubelet docker flanneld;
do
systemctl restart $services;
systemctl enable $services;
systemctl status $services;