1. 程式人生 > >Kubernetes(K8S)叢集在centos7.4下建立

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
檢查
[[email protected] ~]#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/