Kubernetes第一篇:集群安装及问题解决
一.目的:
安装kubernetes集群,为进行集群演练及实战做准备。
二.所需材料:
master(k8s1):10.10.11.12 node1(k8s2):10.10.10.217
三.安装步骤:
1.Master机器安装:
安装epel-release源
yum -y install epel-release
关闭防火墙服务和SELinx
systemctl stop firewalld systemctl disable firewalld setenforce 0
yum -y install etcd kubernetes-master
安装完成后,进入配置阶段,打开并编辑/etc/etcd/etcd.conf文件,如下所示:
#[Member] ETCD_NAME=default #检查此处 #ETCD_CORS="" ETCD_DATA_DIR="/var/lib/etcd/default.etcd" #ETCD_WAL_DIR="" #ETCD_LISTEN_PEER_URLS="http://localhost:2380" ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" #此处一定要设置成0.0.0.0 #ETCD_MAX_SNAPSHOTS="5" #ETCD_MAX_WALS="5" ETCD_NAME="default" #ETCD_SNAPSHOT_COUNT="100000" #ETCD_HEARTBEAT_INTERVAL="100" #ETCD_ELECTION_TIMEOUT="1000" #ETCD_QUOTA_BACKEND_BYTES="0" #ETCD_MAX_REQUEST_BYTES="1572864" #ETCD_GRPC_KEEPALIVE_MIN_TIME="5s" #ETCD_GRPC_KEEPALIVE_INTERVAL="2h0m0s" #ETCD_GRPC_KEEPALIVE_TIMEOUT="20s" # #[Clustering] #ETCD_INITIAL_ADVERTISE_PEER_URLS="http://localhost:2380" ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379" #检查此处 #ETCD_DISCOVERY="" #ETCD_DISCOVERY_FALLBACK="proxy" #ETCD_DISCOVERY_PROXY="" #ETCD_DISCOVERY_SRV="" #ETCD_INITIAL_CLUSTER="default=http://localhost:2380" #ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster" #ETCD_INITIAL_CLUSTER_STATE="new" #ETCD_STRICT_RECONFIG_CHECK="true" #ETCD_ENABLE_V2="true"
备注:ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379" #此处一定要设置成0.0.0.0,否则node启动时会报错:Failed to start Flanneld overlay address etcd agent.
编辑核心配置文件:/etc/kubernetes/apiserver
### # kubernetes system config # # The following values are used to configure the kube-apiserver # # The address on the local server to listen to. KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" #此处默认为127.0.0.1,但一定要设置成0.0.0.0 # The port on the local server to listen on. KUBE_API_PORT="--port=8080" # Port minions listen on KUBELET_PORT="--kubelet-port=10250" # Comma separated list of nodes in the etcd cluster KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379" # Address range to use for services KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16" # default admission control policies KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota" # Add your own! KUBE_API_ARGS=""
备注:KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0" #此处默认为127.0.0.1,但一定要设置成0.0.0.0,否则node1无法注册成功,主机运行kubectl get node时,node1状态为:NotReady
启动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
在etcd中设置flannel网络,请注意,此步骤需要在上面启动的情况下进行:
etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'
master机器安装完成。
2.node1机器安装:
首先安装flannel和kubernetes-node:
yum -y install flannel kubernetes-node
然后配置flannel的ETCD,配置文件地址:/etc/sysconfig/flanneld
FLANNEL_ETCD="http://10.10.11.12:2379" FLANNEL_ETCD_KEY="/atomic.io/network"
配置Kubernetes的配置文件:/etc/kubernetes/config
### # kubernetes system config # # The following values are used to configure various aspects of all # kubernetes services, including # # kube-apiserver.service # kube-controller-manager.service # kube-scheduler.service # kubelet.service # kube-proxy.service # logging to stderr means we get it in the systemd journal KUBE_LOGTOSTDERR="--logtostderr=true" # journal message level, 0 is debug KUBE_LOG_LEVEL="--v=0" # Should this cluster be allowed to run privileged docker containers KUBE_ALLOW_PRIV="--allow-privileged=false" # How the controller-manager, scheduler, and proxy find the apiserver KUBE_MASTER="--master=http://10.10.11.12:8080" #只需要修改此处的IP为masterIP即可。
及配置文件:/etc/kubernetes/kubelet
### # kubernetes kubelet (minion) config # The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces) KUBELET_ADDRESS="--address=127.0.0.1" #此处应配置为0.0.0.0,但不修改也能正常运行。 # The port for the info server to serve on KUBELET_PORT="--port=10250" #打开端口 # You may leave this blank to use the actual hostname KUBELET_HOSTNAME="--hostname-override=10.10.10.217" #此处为本机k8s2的IP # location of the api-server KUBELET_API_SERVER="--api-servers=http://10.10.11.12:8080" #master机器IP # pod infrastructure container KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest" # Add your own! KUBELET_ARGS=""
设置完成后,启动kube-proxy、kubelet、docker、flanneld等服务,并设置随机启动。
for SERVICES in kube-proxy kubelet docker flanneld;do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES; done
四.集群验证:
验证Kubernetes是否启动成功,在master机器上运行:
[root@k8s1 ~]# kubectl get node NAME STATUS AGE 10.10.10.217 Ready 22m [root@k8s1 ~]#