CentOS 7 一键安装单机版Kubernetes脚本分享

Kubernetes

最近把www.kubernetes.org.cn 网站的文档大概看完了一遍,对kubernetes的了解也算是入门了,对于新人来讲如何熟悉kubernetes我以为不该该先从配置繁琐的环境开始,而是先熟悉软件的基本命令用法,渐渐再加深对概念的理解渗透。最近也折腾了很久,分享个一键部署kubernetes的脚本吧。node

shell脚本

#!/usr/bin/env bash 
yum install -y epel-release ;
sed -e 's!^mirrorlist=!#mirrorlist=!g' -e 's!^#baseurl=!baseurl=!g'   -e 's!//download\.fedoraproject\.org/pub!//mirrors.ustc.edu.cn!g'  -e 's!http://mirrors\.ustc!https://mirrors.ustc!g'  -i /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel-testing.repo ;
yum makecache ;
yum update -y;
yum install htop net-tools etcd htop vim e4fsprogs iptables kubernetes openssh-server   byobu git zsh -y ;

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" ;


for SERVICES in ` ls /usr/lib/systemd/system/kub* | awk -F '/' '{print $6}' ` docker   ; do  echo $SERVICES ; done ;

for SERVICES in ` ls /usr/lib/systemd/system/kub* | awk -F '/' '{print $6}' ` docker etcd ; do systemctl restart $SERVICES ; systemctl enable  $SERVICES ; systemctl status $SERVICES ; done ;


sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" ;


## test kubectl
kubectl get nodes ;

# reboot system
#systemctl reboot ;复制代码

验证安装

最后kubectl get nodes 验证是否安装成功:输出以下就对了。git

[root@6c0cf7c29422 /]# kubectl get nodes
NAME        STATUS    AGE
127.0.0.1   Ready     11m复制代码

我是在 Docker容器内部再运行一套Docker环境来验证这个脚本的,脚本中有些安装的软件如 e4fsprogs iptables 是启动内部Docker容器所必须的。github

启动CentOS容器:

docker run -d --name=ctj2 --restart=always -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup centos /usr/sbin/initdocker

进入容器内部:
docker exec -it ctj2 bashshell

而后运行上面的部署脚本试试吧!vim

相关文章
相关标签/搜索