Kubernetes(K8S)集群在centos7.4下创建

自己在搭Kubernetes(K8S)集群下遇到的坑写一点随笔。

本次采用192.168.60.21,192.168.60.22,192.168.60.23作为需要装的服务器。

master需要安装etcd, flannel,docker, kubernetes   192.168.60.21
yum –y install etcd
yum –y install flannel
yum –y install docker
yum –y install kubernetes
分支上安装flannel,docker,kubernetes 
yum –y install flannel
yum –y install docker
yum –y install kubernetes
在master上修改etcd的配置文件
vim /etc/etcd/etcd.conf
ETCD_NAME="default"
ETCD_LISTEN_CLIENT_URLS="http:// 192.168.60.21:2379,http://127.0.0.1:2379"
ETCD_ADVERTISE_CLIENT_URLS="http:// 192.168.60.21:2379"
启动
systemctl enable etcd.service
systemctl  start etcd.service
检查
[root@k8s-master ~]#etcdctl -C http:// 192.168.60.21:2379 cluster-health
member 8e9e05c52164694d is healthy: got healthy result from http://10.0.0.11:2379
cluster is healthy
主机配置kube-controller-manager
编写/usr/lib/systemd/system/kube-controller.service文件。
Description=Kubernetes Controller Manager
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
 
[Service]
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/controller-manager
ExecStart=/usr/bin/kube-controller-manager \
                  $KUBE_LOGTOSTDERR \
                  $KUBE_LOG_LEVEL \
                  $KUBE_MASTER \
                  $KUBE_CONTROLLER_MANAGER_ARGS
Restart=on-failure
LimitNOFILE=65536
 
[Install]
WantedBy=multi-user.target
 
将/usr/lib/systemd/system下和/etc/kubernetes下的文件将里面的ip地址配成192.168.60.21
启动
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler kube-proxy kubelet flanneld; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done
分支上192.168.60.22上
修改config文件vim /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://192.168.60.21:8080"
KUBE_ETCD_SERVERS="--etcd_servers=http://192.168.60.21:2379"
修改kubelet
vim /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=192.168.60.22"
# 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=192.168.60.22"
# location of the api-server
KUBELET_API_SERVER="--api-servers=http://192.168.60.21:8080"
# pod infrastructure container
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
# Add your own!
KUBELET_ARGS=""
分支上192.168.60.23上类似
for SERVICES in kube-proxy kubelet flanneld; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done
检查
kubectl -s 192.168.60.21:8080 get all查看节点情况
至于为什么加上-s 192.168.60.21:8080呢,因为不佳时就报错,全网络也没有特别合适的解决方案
参考https://www.cnblogs.com/lyq863987322/p/8516958.html,http://www.cnblogs.com/lyzw/p/6016789.html,https://jimmysong.io/posts/kubernetes-installation-on-centos/

猜你喜欢

转载自www.cnblogs.com/jueshixingkong/p/10188738.html