前提
前提:VirtualBox CentOS7
物理机IP 192.168.18.8
虚拟机1IP:192.168.18.100(VMaster master)
虚拟机2IP:192.168.18.101(VServer1 node1)
虚拟机3IP:192.168.18.102(VServer2 node2)
虚拟机3IP:192.168.18.103(VPrometheus node3)
一、CentOS7 虚拟机IP配置
1.#cd /etc/sysconfig/network-scripts
2.#vi ifcfg-enp0s3
TYPE=Ethernet
DEVICE=enp0s3
NAME=enp0s3
ONBOOT=yes
DEFROUTE=yes
BOOTPROTO=static
IPADDR=192.168.18.101
NETMASK=255.255.255.0
DNS1=192.168.18.1
GATEWAY=192.168.18.1
BROADCAST=192.168.18.1
3.#service network restart
4.#ip address
二:虚拟机hostname 设置(重启生效)
1.#hostname
或
#hostnamectl
2.#vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=VServer1
3.#vi /etc/hosts
最后一行加上修改后的IP地址及对应的主机名:
192.168.18.101 VServer1
4.#vi /etc/hostname
5.#reboot
重启虚拟机
centos7系统,有systemctl restart systemd-hostnamed服务,重启这个服务即可
#systemctl restart systemd-hostnamed
6.#hostname
或
#hostnamectl
7.#yum update
CentOS升级(包括系统版本和内核版本)
8.#reboot
重启虚拟机
三.K8S安装前准备
1.关闭firewalld,并禁止开机启动
# systemctl stop firewalld.service #停止firewall
# systemctl disable firewalld.service #禁止firewall开机启动
2.安装ntp服务
# yum install -y ntp wget net-tools
# systemctl start ntpd
# systemctl enable ntpd
四、K8S Master安装配置
1.安装Kubernetes Master
# yum install -y kubernetes etcd
2.编辑/etc/etcd/etcd.conf 使etcd监听所有的ip地址,确保下列行没有注释,并修改为下面的值
# vi /etc/etcd/etcd.conf
# [member]
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="https://0.0.0.0:2380"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
#[clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://192.168.18.100:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://192.168.18.100:2379"
ETCD_INITIAL_CLUSTER="default=http://192.168.18.100:2380"
3.编辑Kubernetes API server的配置文件 /etc/kubernetes/apiserver,确保下列行没有被注释,并为下列的值
# vi /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=127.0.0.1"
KUBE_API_ADDRESS="--address=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://192.168.18.100: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=""
4.启动etcd, kube-apiserver, kube-controller-manager and kube-scheduler服务,并设置开机自启
#mkdir /script
#touch kubenetes_service.sh
#vi kubenetes_service.sh
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
#chmod 777 kubenetes_service.sh
#sh /script/kubenetes_service.sh
5.在etcd中定义flannel network的配置,这些配置会被flannel service下发到nodes:
# etcdctl mk /centos.com/network/config '{"Network":"172.17.0.0/16"}'
6.添加iptables规则,允许相应的端口
# iptables -I INPUT -p tcp --dport 2379 -j ACCEPT
# iptables -I INPUT -p tcp --dport 10250 -j ACCEPT
# iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
# iptables-save
#瞄一眼现有的iptables规则
#iptables -L -n
五、K8S Nodes安装配置
1.使用yum安装kubernetes 和 flannel
# yum install -y flannel kubernetes
2.为flannel service配置etcd服务器,编辑/etc/sysconfig/flanneld文件中的下列行以连接到master
#vi /etc/sysconfig/flanneld
FLANNEL_ETCD="http://192.168.18.100:2379" #改为etcd服务器的ip
FLANNEL_ETCD_PREFIX="/centos.com/network"
3.编辑/etc/kubernetes/config 中kubernetes的默认配置,确保KUBE_MASTER的值是连接到Kubernetes master API server:
#vi /etc/kubernetes/config
KUBE_MASTER="--master=http://192.168.18.100:8080"
4.编辑/etc/kubernetes/kubelet 如下行:
node1:
# vi /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname_override=192.168.18.101"
KUBELET_API_SERVER="--api_servers=http://192.168.18.100:8080"
KUBELET_ARGS=""
node2:
# vi /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname_override=192.168.18.102"
KUBELET_API_SERVER="--api_servers=http://192.168.18.100:8080"
KUBELET_ARGS=""
5.启动kube-proxy, kubelet, docker 和 flanneld services服务,并设置开机自启
#mkdir /script
#touch kubernetes_node_service.sh
#vi kubernetes_node_service.sh
for SERVICES in kube-proxy kubelet docker flanneld; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
#chmod 777 kubernetes_node_service.sh
#sh /script/kubernetes_node_service.sh
6.添加iptables规则:
# iptables -I INPUT -p tcp --dport 2379 -j ACCEPT
# iptables -I INPUT -p tcp --dport 10250 -j ACCEPT
# iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
# iptables-save
#瞄一眼现有的iptables规则
#iptables -L -n
已有
0 人发表留言,猛击->>
这里<<-参与讨论
ITeye推荐