c4rt1y

k8s之yum安装

0x01.Kubernetes介绍

Kubernetes 是一个自动化部署、伸缩和操作应用程序容器的开源平台。使用Kubernetes,你可以快速、高效地满足用户以下的需求,快速精准地部署应用程序,即时伸缩你的应用程序,无缝展现新特征,限制硬件用量仅为所需资源。Kubernetes(k8s)是Google开源的容器集群管理系统(谷歌内部:Borg)。在Docker技术的基础上,为容器化的应用提供部署运行、资源调度、服务发现和动态伸缩等一系列完整功能,提高了大规模容器集群管理的便捷性。

0x02.服务器基础配置

## master 
#添加hosts
cat >> /etc/hosts << EOF
10.10.10.10 k8s-master
10.10.10.20 k8s-node-1
10.10.10.30 k8s-node-2
EOF

#设置主机名
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
#关闭selinux
systemctl stop firewalld
systemctl disable firewalld
#关闭防火墙
yum -y install ntp
systemctl start ntpd
systemctl enable ntpd
#ntp时间同步
HOSTNAME IP 组件
k8s-master 10.10.10.10 etcd、 kube-apiserver、kube-controller- manager、 kube-scheduler
k8s-node-1 10.10.10.20 docker、 kubelet、 kube-proxy
k8s-node-2 10.10.10.30 docker、 kubelet、 kube-proxy

0x03.安装master节点

## master节点

#首先修改hostname(修改完毕重启一个终端)
hostnamectl set-hostname k8s-master

##master节点安装主控端
yum -y install etcd kubernetes-master


#ip=`ifconfig|grep inet|awk '{print $2}'|grep 10`

#备份需要修改的文件
cp /etc/etcd/etcd.conf /etc/etcd/etcd.conf.bak
cp /etc/kubernetes/config /etc/kubernetes/config.bak
cp /etc/kubernetes/apiserver /etc/kubernetes/apiserver.bak
#获取hostname ip=$HOSTNAME
#修改etcd文件
cat > /etc/etcd/etcd.conf << EOF
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_NAME="default"
ETCD_ADVERTISE_CLIENT_URLS="http://$ip:2379"
EOF

#修改kubernetes配置文件
cat > /etc/kubernetes/config << EOF
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://$ip:8080"
EOF

#修改apiserver配置文件
cat > /etc/kubernetes/apiserver << EOF
KUBE_API_ADDRESS="--address=0.0.0.0"
KUBE_ETCD_SERVERS="--etcd-servers=http://$ip:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
KUBE_API_ARGS=""
EOF

#查看$ip变量修改
cat /etc/etcd/etcd.conf 
cat /etc/kubernetes/config
cat /etc/kubernetes/apiserver

#启动文件,添加启动项,查看状态
for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done

#设置k8s网络连接
etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'

0x04.安装node节点

##node节点自动化

#首先修改hostname(,两台不一样的地址,修改完毕重启一个终端)
hostnamectl set-hostname k8s-node-1

#安装服务端
yum -y install flannel kubernetes-node
#yum install *rhsm* -y

#本机hostname
ip=$HOSTNAME
#master地址
masterip="k8s-master"

#备份需要修改的文件
cp  /etc/sysconfig/flanneld  /etc/sysconfig/flanneld.bak
cp /etc/kubernetes/config /etc/kubernetes/config.bak
cp /etc/kubernetes/kubelet /etc/kubernetes/kubelet.bak

#设置与master网络连接
cat >  /etc/sysconfig/flanneld << EOF
FLANNEL_ETCD_ENDPOINTS="http://$masterip:2379"
FLANNEL_ETCD_KEY="/atomic.io/network"
EOF

#修改kubernetes配置文件
cat > /etc/kubernetes/config << EOF
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://$masterip:8080"
EOF

#修改kubelet配置文件
cat > /etc/kubernetes/kubelet << EOF
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=$ip"
KUBELET_API_SERVER="--api-servers=http://$masterip:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""
EOF

#查看$ip变量修改了
cat /etc/kubernetes/kubelet
cat /etc/kubernetes/config
cat /etc/sysconfig/flanneld

#启动文件,添加启动项,查看状态
for SERVICES in kube-proxy kubelet docker flanneld; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
done

0x05.验证

##master上输入
[root@k8s-master /root] kubectl get node
NAME         STATUS    AGE
k8s-node-1   Ready     50s
k8s-node-2   Ready     20s	

0x06.资料来源

http://vincentwang.top/2016/02/23/Kubernetes-Cluster-with-3-minions-on-CentOS-7/
http://www.cnblogs.com/xkops/p/6169034.html
https://blog.csdn.net/dream_broken/article/details/52954069
GoTop