Kubernetes v1.10 快速安装(只需三步)

K8sv1.10快速安装,只需三步即可(执行三个.sh脚本,下面贴出了脚本内容,直接复制即可)

#测试环境centos 7.3 , docker 17.06

  • 第一步:初始化环境

~]# vi env_set.sh

 1 #!/bin/bash
 2 
 3 #check
 4 
 5 [[ $UID -ne 0 ]]&& { echo "Must run in root user !";exit; }
 6 
 7 echo '# 基础配置#
 8 
 9 #关闭防火墙
10 
11 #关闭Selinux
12 
13 #关闭Swap
14 
15 #内核配置
16 
17 #防火墙#
18 
19 systemctl stopfirewalld &>/dev/null
20 
21 systemctl disablefirewalld &>/dev/null
22 
23 [[ -f /etc/init.d/ufw]] && { ufw disable;}
24 
25 [[ -f/etc/init.d/iptables ]] && { /etc/init.d/iptables stop; }
26 
27 #关闭Selinux
28 
29 setenforce  0 &>/dev/null
30 
31 sed -i"s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
32 
33 sed -i"s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
34 
35 sed -i"s/^SELINUX=permissive/SELINUX=disabled/g" /etc/sysconfig/selinux
36 
37 sed -i"s/^SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config
38 
39 #关闭Swap
40 
41 swapoff -a
42 
43 sed's/.*swap.*/#&/' /etc/fstab &>/dev/null
44 
45 #内核#
46 
47 cat </etc/sysctl.d/k8s.conf
48 
49 net.ipv4.ip_forward =1
50 
51 net.bridge.bridge-nf-call-ip6tables= 1
52 
53 net.bridge.bridge-nf-call-iptables= 1
54 
55 vm.swappiness=0
56 
57 EOF
58 
59 sysctl -p/etc/sysctl.d/k8s.conf &>/dev/null
60 
61 echo "sysctl -p/etc/sysctl.d/k8s.conf" >>/etc/profile
62 
63 echo "#myset
64 
65 * soft nofile 65536
66 
67 * hard nofile 65536
68 
69 * soft nproc 65536
70 
71 * hard nproc 65536
72 
73 * soft  memlock unlimited
74 
75 * hard memlock  unlimited
76 
77 ">>/etc/security/limits.conf
78 
79 #hosts
点开查看env_set.sh脚本
  • 第二步:下载相关组件

~]# vi download.sh

 1 #安装kubelet kubeadm
 2 
 3 curl -s http://elven.vip/ks/sh/kubelet.sh|bash
 4 
 5 echo '下载K8S相关镜像'
 6 
 7 MyUrl=registry.cn-shanghai.aliyuncs.com/alik8s
 8 
 9 images=(kube-proxy-amd64:v1.10.0kube-controller-manager-amd64:v1.10.0 kube-scheduler-amd64:v1.10.0kube-apiserver-amd64:v1.10.0 etcd-amd64:3.1.12kubernetes-dashboard-amd64:v1.8.3 heapster-grafana-amd64:v4.4.3heapster-influxdb-amd64:v1.3.3 heapster-amd64:v1.4.2k8s-dns-dnsmasq-nanny-amd64:1.14.8 k8s-dns-sidecar-amd64:1.14.8k8s-dns-kube-dns-amd64:1.14.8 pause-amd64:3.1)
10 
11 #
12 
13 for imageName in${images[@]} ; do
14 
15   docker pull $MyUrl/$imageName
16 
17   docker tag $MyUrl/$imageNamek8s.gcr.io/$imageName
18 
19   docker rmi $MyUrl/$imageName
20 
21 done
22 
23 #
24 
25 docker pull$MyUrl/flannel:v0.10.0-amd64
26 
27 docker tag$MyUrl/flannel:v0.10.0-amd64 quay.io/coreos/flannel:v0.10.0-amd64
28 
29 docker rmi$MyUrl/flannel:v0.10.0-amd64
30 
31 echo '下载yml文件,部署flannel网络,dashboard用到'
32 
33 mkdir -p$HOME/k8s/heapster ; cd $HOME/
34 
35 YmlUrl=http://elven.vip/ks/k8s/oneinstall/yml
36 
37 curl -s$YmlUrl/kube-flannel.yml >k8s/kube-flannel.yml
38 
39 curl -s$YmlUrl/kubernetes-dashboard.yaml >k8s/kubernetes-dashboard.yaml
40 
41 curl -s$YmlUrl/heapster-rbac.yaml >k8s/heapster-rbac.yaml
42 
43 curl -s$YmlUrl/heapster/influxdb.yaml >k8s/heapster/influxdb.yaml
44 
45 curl -s$YmlUrl/heapster/heapster.yaml >k8s/heapster/heapster.yaml
46 
47 curl -s$YmlUrl/heapster/grafana.yaml >k8s/heapster/grafana.yaml
48 
49 echo 
50 
51 echo '镜像列表'
52 
53 docker images |egrep'k8s.gcr.io|quay.io'
54 
55 echo 
56 
57 echo "yml部署文件"
58 
59 ls -l $HOME/k8s/
60 
61 echo 
点开查看download.sh脚本
  • 第三步:安装部署k8s

~]# vi install.sh

  1 #!/bin/bash
  2 
  3 #k8s v1.10 master 单节点安装
  4 
  5 #check
  6 
  7 [[ $UID -ne 0 ]]&& { echo "Must run in root user !";exit; }
  8 
  9 #重置#
 10 
 11 kubeadm reset&>/dev/null
 12 
 13 echo -e"\033[32m初始化安装K8S Master\033[0m"
 14 
 15 kubeadm init--kubernetes-version=v1.10.0 --pod-network-cidr=10.244.0.0/16 |tee /tmp/install.log
 16 
 17 echo 
 18 
 19 echo -e"\033[32mk8s node节点代码保存到$HOME/k8s.add.node.txt\033[0m"
 20 
 21 grep 'kubeadm join'/tmp/install.log >$HOME/k8s.add.node.txt
 22 
 23 rm -f/tmp/install.log
 24 
 25 sleep 2
 26 
 27 #默认token有效期24小时,生成一个永不过期的
 28 
 29 Token=`kubeadm tokencreate --ttl 0`
 30 
 31 # echo $Token
 32 
 33 # kubeadm token list
 34 
 35 sed -i -r"s#(.*) --token (.*) --discovery(.*)#\1 --token $Token --discovery\3#"$HOME/k8s.add.node.txt
 36 
 37 #kubectl认证
 38 
 39 exportKUBECONFIG=/etc/kubernetes/admin.conf
 40 
 41 echo "exportKUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
 42 
 43 ##
 44 
 45 echo "# used forkubectl ,k8s" >/etc/profile
 46 
 47 echo "exportKUBECONFIG=/etc/kubernetes/admin.conf" >>/etc/profile
 48 
 49 sleep 5
 50 
 51 echo -e"\033[32m查看K8S状态\033[0m"
 52 
 53 kubectl get cs
 54 
 55 #让master也运行pod
 56 
 57 kubectl taint nodes--all node-role.kubernetes.io/master-
 58 
 59 cd $HOME/
 60 
 61 echo -e"\033[32m部署flannel网络 \033[0m"
 62 
 63 kubectl create -fk8s/kube-flannel.yml
 64 
 65 sleep 5
 66 
 67 echo 
 68 
 69 echo -e"\033[32m部署dashboard\033[0m"
 70 
 71 kubectl create -fk8s/kubernetes-dashboard.yaml
 72 
 73 #dashboard监控图形化
 74 
 75 sleep 5
 76 
 77 kubectl create -fk8s/heapster/
 78 
 79 kubectl create -fk8s/heapster-rbac.yaml
 80 
 81 sleep 10
 82 
 83 echo -e"\033[32m查看pod\033[0m"
 84 
 85 kubectl get pods--all-namespaces
 86 
 87 echo 
 88 
 89 echo -e"\033[32mdashboard登录令牌,保存到$HOME/k8s.token.dashboard.txt\033[0m"
 90 
 91 kubectl -nkube-system describe secret $(kubectl -n kube-system get secret | grepadmin-user | awk '{print $1}') |awk '/token:/{print$2}'>$HOME/k8s.token.dashboard.txt
 92 
 93 echo 'dashboard登录令牌如下:'
 94 
 95 echo 
 96 
 97 cat$HOME/k8s.token.dashboard.txt
 98 
 99 echo 
100 
101 echo 'dashboard登录地址 https://本机IP:30000即: '
102 
103 IP=`sed -r 's#^.*join(.*):6443.*$#\1#' $HOME/k8s.add.node.txt`
104 
105 echo "  https://$IP:30000"
106 
107 echo 
108 
109 echo '登录dashboard,输入令牌token'
110 
111 echo '推荐火狐浏览器'
112 
113 echo '若提示不安全的连接, 高级->添加例外'
114 
115 echo 
116 
117 echo 
118 
119 echo -e"\033[32m添加k8s node节点代码如下:\033[0m"
120 
121 echo 
122 
123 cat$HOME/k8s.add.node.txt
124 
125 echo 
126 
127 echo  "重新登录查看Node    kubectl getnodes"
128 
129 echo 
130 
131 exit
点开查看install.sh脚本

# 若安装失败,重新执行

 

至此安装完成,访问dashboard登录地址https://本机IP:30000

Kubernetes v1.10 快速安装(只需三步)_第1张图片

 

  • 附:

1、K8S节点加入命令:kubeadm token create --print-join-command (适用于1.9版本之后)

2、Kubeadm 初始化时提示:

unable toget URL "https://dl.k8s.io/release/stable-1.10.txt":Get https://storage.googleapis.com/kubernetes-release/release/stable-1.10.txt:dial tcp 216.58.200.48:443: i/o timeout

解决方案:

需要指定k8s版本:kubeadm init --kubernetes-version=1.10.0…………

3、执行kubectl  get  pods提示:The connection to theserver localhost:8080 was refused - did you specify the right host or port?

解决方案:

$ sudo cp /etc/kubernetes/admin.conf $HOME/

$sudochown $(id -u):$(id -g) $HOME/admin.conf

$export KUBECONFIG=$HOME/admin.conf

$ sudo cp /etc/kubernetes/kubelet.conf $HOME/

$sudochown $(id -u):$(id -g) $HOME/kubelet.conf

$export KUBECONFIG=$HOME/kubelet.conf

 

  -End-



Kubernetes v1.10 快速安装(只需三步)_第2张图片@Cooper_73 @gjs_73archer

更多精彩内容请关注微信公众号“73号弓箭手

博客主页链接: https://www.cnblogs.com/cooper-73/


 

转载于:https://www.cnblogs.com/cooper-73/p/9685580.html

你可能感兴趣的:(Kubernetes v1.10 快速安装(只需三步))