CentOS7安裝Kubernetes


CentOS7安裝Kubernetes

安裝Kubernetes時候需要一台機器作為管理機器,1台或者多台機器作為集群中的節點。

系統信息:

Hosts:

請將IP地址換成自己環境的地址.

centos-master = 192.168.164.130
centos-minion-1 = 192.168.164.131
centos-minion-2 = 192.168.164.132
centos-minion-3 = 192.168.164.133

安裝准備

*. 在所有的centos-{master,minion-n}上創建文件 /etc/yum.repos.d/virt7-docker-common-release.repo,同時輸入以下內容.

[virt7-docker-common-release]
name=virt7-docker-common-release
baseurl=http://cbs.centos.org/repos/virt7-docker-common-release/x86_64/os/
gpgcheck=0

*. 在所有的機器上centos-{master,minion-n},安裝Kubernetes, etcd flannel

yum -y install --enablerepo=virt7-docker-common-release kubernetes etcd flannel

*. 在所有的機器上centos-{master,minion-n}添加hosts信息。將下列信息添加到/etc/hosts

echo "192.168.164.130 centos-master
192.168.164.131	centos-minion-1
192.168.164.132 centos-minion-2
192.168.164.133 centos-minion-3" >> /etc/hosts

*. 編輯所有機器的/etc/kubernetes/config文件。

# 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 replication controller and scheduler find the kube-apiserver
KUBE_MASTER="--master=http://centos-master:8080"

*. 關閉selinux與防火牆

#關閉selinux
將文件的/etc/sysconfig/selinux 
SELINUX=enable
改成
SELINUX=disabled
#關閉防火牆
setenforce 0
systemctl disable iptables-services firewalld
systemctl stop iptables-services firewalld

Master服務器上的操作,修改kubernetes服務器配置文件

修改etcd配置文件 /etc/etcd/etcd.conf

# [member]
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"

#[cluster]
ETCD_ADVERTISE_CLIENT_URLS="http://0.0.0.0:2379"

修改kubernetes服務器配置文件/etc/kubernetes/apiserver

# The address on the local server to listen to.
KUBE_API_ADDRESS="--address=0.0.0.0"

# The port on the local server to listen on.
KUBE_API_PORT="--port=8080"

# Port kubelets listen on
KUBELET_PORT="--kubelet-port=10250"

# Comma separated list of nodes in the etcd cluster
KUBE_ETCD_SERVERS="--etcd-servers=http://centos-master:2379"

# Address range to use for services
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"

# Add your own!
KUBE_API_ARGS=""

啟動ectd同時設置一下,使網絡地址足夠使用。

systemctl start etcd
etcdctl mkdir /kube-centos/network
etcdctl mk /kube-centos/network/config "{ \"Network\": \"172.30.0.0/16\", \"SubnetLen\": 24, \"Backend\": { \"Type\": \"vxlan\" } }"

修改flannel 配置文件/etc/sysconfig/flanneld

# Flanneld configuration options

# etcd url location.  Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://centos-master:2379"

# etcd config key.  This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/kube-centos/network"

# Any additional options that you want to pass
#FLANNEL_OPTIONS=""

啟動服務

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler flanneld; do
	systemctl restart $SERVICES
	systemctl enable $SERVICES
	systemctl status $SERVICES
done

Minion服務器上的操作,修改kubernetesde kubelet配置文件

配置 kubelet 。啟動 kubeletproxy

修改配置文件/etc/kubernetes/kubelet

# The address for the info server to serve on
KUBELET_ADDRESS="--address=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
# Check the node number!
KUBELET_HOSTNAME="--hostname-override=centos-minion-n"

# Location of the api-server
KUBELET_API_SERVER="--api-servers=http://centos-master:8080"

# Add your own!
KUBELET_ARGS=""

修改flannel 的配置文件。/etc/sysconfig/flanneld

# Flanneld configuration options

# etcd url location.  Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://centos-master:2379"

# etcd config key.  This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/kube-centos/network"

# Any additional options that you want to pass
#FLANNEL_OPTIONS=""

啟動所有節點上的相關服務

for SERVICES in kube-proxy kubelet flanneld docker; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done

設置kubectl

kubectl config set-cluster default-cluster --server=http://centos-master:8080
kubectl config set-context default-context --cluster=default-cluster --user=default-admin
kubectl config use-context default-context

安裝完成

可以測試一下是否能看到所有節點

# kubectl get nodes
NAME              STATUS    AGE
centos-minion-1   Ready     5m
centos-minion-2   Ready     5m
centos-minion-3   Ready     1m


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM