最近把www.kubernetes.org.cn 網站的文檔大概看完了一遍,對kubernetes的瞭解也算是入門了,對於新人來講如何熟悉kubernetes我以爲不該該先從配置繁瑣的環境開始,而是先熟悉軟件的基本命令用法,漸漸再加深對概念的理解滲透。最近也折騰了很久,分享個一鍵部署kubernetes的腳本吧。node
#!/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
docker run -d --name=ctj2 --restart=always -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup centos /usr/sbin/init
docker
進入容器內部:docker exec -it ctj2 bash
shell
而後運行上面的部署腳本試試吧!vim