码迷,mamicode.com
首页 > Web开发 > 详细

CentOS 7部署Kubernetes单机的shell脚本

时间:2020-05-30 10:44:21      阅读:90      评论:0      收藏:0      [点我收藏+]

标签:memory   shell脚本   tee   tin   firewall   text   commit   col   account   

研究了个一键部署Kubernetes的shell脚本,经验证可以在 CentOS 7 1804 及 CentOS 7 1810 上成功部署Kubernetes单机环境,但需要在执行脚本前做好OS环境的初始化。
以下是该脚本的内容:

#!/bin/sh
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.original
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
yum clean all && yum makecache && yum -y update
hostnamectl set-hostname kubernetes-single
systemctl stop firewalld && systemctl disable firewalld
sed -i ‘s/^SELINUX=./SELINUX=disabled/‘ /etc/selinux/config && setenforce 0
swapoff -a
sed -ri ‘s/.
swap./#&/‘ /etc/fstab
echo "192.168.207.132 kubernetes-master " >> /etc/hosts
yum install -y etcd kubernetes
sed -i "s/--selinux-enabled --log-driver=journald --signature-verification=false/--selinux-enabled=false --insecure-registry gcr.io/g" /etc/sysconfig/docker
sed -i "s/--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota/--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota/g" /etc/kubernetes/apiserver
systemctl start etcd
systemctl start docker
systemctl start kube-apiserver
systemctl start kube-controller-manager
systemctl start kube-scheduler
systemctl start kubelet
systemctl start kube-proxy
yum install -y
rhsm*
yum install -y wget
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
rm -rf python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest
iptables -P FORWARD ACCEPT

以下内容是在为做OS初始化的情况下执行该脚本的验证记录,OS环境为 CentOS 7 1810 :

[googlebigtable@localhost ~]$ su - root
Password:
[root@localhost ~]# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.original
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2020-05-29 07:42:17-- http://mirrors.163.com/.help/CentOS7-Base-163.repo
Resolving mirrors.163.com (mirrors.163.com)... 59.111.0.251
Connecting to mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1572 (1.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

100%[==================================================================================================>] 1,572 --.-K/s in 0s

2020-05-29 07:42:18 (552 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [1572/1572]

[root@localhost ~]# ls -F /etc/yum.repos.d/
CentOS-Base.repo CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
CentOS-Base.repo.original CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 21738.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: PackageKit
Memory : 136 M RSS (479 MB VSZ)
Started: Fri May 29 07:40:28 2020 - 02:18 ago
State : Sleeping, pid: 21738
^C
Exiting on user cancel.
[root@localhost ~]# kill -s 9 21738
[root@localhost ~]# ps -aux | grep yum
root 22376 0.0 0.0 112708 968 pts/0 S+ 07:44 0:00 grep --color=auto yum
[root@localhost ~]# yum clean all
BDB2053 Freeing read locks for locker 0x1848: 21738/139878471358272
BDB2053 Freeing read locks for locker 0x184a: 21738/139878471358272
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00:00
(2/10): base/7/x86_64/primary_db | 6.1 MB 00:00:05
(3/10): extras/7/x86_64/primary_db | 194 kB 00:00:01
(4/10): extras/7/x86_64/filelists_db | 205 kB 00:00:01
(5/10): extras/7/x86_64/other_db | 122 kB 00:00:00
(6/10): base/7/x86_64/filelists_db | 7.1 MB 00:00:08
(7/10): updates/7/x86_64/filelists_db | 980 kB 00:00:03
(8/10): updates/7/x86_64/other_db | 183 kB 00:00:00
(9/10): updates/7/x86_64/primary_db | 1.3 MB 00:00:03
(10/10): base/7/x86_64/other_db | 2.6 MB 00:00:06
Metadata Cache Created
[root@localhost ~]#

[root@localhost ~]# yum -y update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
...............................................................................................................................
Complete!
[root@localhost ~]#

[root@localhost ~]# ls -F
anaconda-ks.cfg initial-setup-ks.cfg
[root@localhost ~]# pwd -P
/root
[root@localhost ~]# gedit kubernetessingle.sh
[root@localhost ~]# ls -F
anaconda-ks.cfg initial-setup-ks.cfg kubernetessingle.sh
[root@localhost ~]# chmod +x kubernetessingle.sh
[root@localhost ~]# ll
total 12
-rw-------. 1 root root 1927 May 29 07:17 anaconda-ks.cfg
-rw-r--r--. 1 root root 1975 May 29 07:35 initial-setup-ks.cfg
-rwxr-xr-x. 1 root root 2176 May 29 07:50 kubernetessingle.sh
[root@localhost ~]#
[root@localhost ~]# ./kubernetessingle.sh
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Loaded plugins: fastestmirror, langpacks
.............................................................................................................
Status: Downloaded newer image for registry.access.redhat.com/rhel7/pod-infrastructure:latest
[root@localhost ~]#
[root@localhost ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
[root@localhost ~]# kubectl get nodes
NAME STATUS AGE
127.0.0.1 Ready 1h
[root@localhost ~]# kubectl describe nodes 127.0.0.1 | grep -E ‘(Roles|Taints)‘
Taints: <none>
[root@localhost ~]#
[root@localhost ~]# kubectl run httpd-app --image=httpd --replicas=2
deployment "httpd-app" created
[root@localhost ~]#

说明:该脚本如果要在生产环境下直接使用,仍需根据资源分配状况做定制化设定。

孟伯,20200529

交流联系:微信 1807479153 ,QQ 1807479153

CentOS 7部署Kubernetes单机的shell脚本

标签:memory   shell脚本   tee   tin   firewall   text   commit   col   account   

原文地址:https://blog.51cto.com/6286393/2499748

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!