官方文档利用Kubeadm安装k8s

2019-03-06  本文已影响0人  amdaous

一、准备环境

所有节点操作:

1.配置好各节点hosts文件
2.关闭系统防火墙
3.关闭Selinux
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
4.关闭swap
5.在/etc/sysctl.conf中添加以下配置
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF

sysctl --system
6.配置yum源
docker yum源
cat >> /etc/yum.repos.d/docker.repo <<EOF
[docker-repo]
name=Docker Repository
baseurl=http://mirrors.aliyun.com/docker-engine/yum/repo/main/centos/7
enabled=1
gpgcheck=0
EOF
kubernetes yum源
cat >> /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF

yum clean all
yum makecache

二、安装docker、kubeadm等

所有节点操作:
yum install -y docker --disableexcludes=docker-repo
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet

三、kubeadm初始化集群

在master上操作:
kubeadm init --image-repository=registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --kubernetes-version=v1.13.0
输出应如下所示:
image.png

注意:请保存输出中的 kubeadm join …………一行命令

要使kubectl为非root用户工作,请运行以下命令,这些命令也是kubeadm init输出的一部分:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
或者,如果是root用户,则可以运行:
export KUBECONFIG=/etc/kubernetes/admin.conf

四、安装flannel网络

在master上操作:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
执行 kubectl get pod -n kube-system 查看pod状态,等待所有pod处于running状态即可。

五、添加计算节点

在计算节点上操作:
执行第三步中保存的 kubeadm join …………命令
在master上查看node添加状态:kubectl get nodes

六、部署dashboard

在master上操作:
1.下载yaml文件
wget
https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard.yaml
2.更改yaml'中的image地址
将kubernetes-dashboard.yaml中的镜像地址改为
registry.cn-qingdao.aliyuncs.com/wangxiaoke/kubernetes-dashboard-amd64:v1.10.0
3.安装
kubectl create -f  kubernetes-dashboard.yaml
查看dashboard的POD是否正常启动,如果正常说明安装成功
[root@node1 ~]# kubectl get pods --namespace=kube-system
NAME                                     READY   STATUS    RESTARTS   AGE
coredns-576cbf47c7-kg8s9                 1/1     Running   0          29h
coredns-576cbf47c7-st599                 1/1     Running   0          29h
etcd-node1.ztpt.com                      1/1     Running   0          29h
kube-apiserver-node1.ztpt.com            1/1     Running   0          29h
kube-controller-manager-node1.ztpt.com   1/1     Running   1          29h
kube-flannel-ds-amd64-79x9h              1/1     Running   0          27h
kube-flannel-ds-amd64-f9fls              1/1     Running   0          26h
kube-flannel-ds-amd64-q7kvx              1/1     Running   0          29h
kube-proxy-242zg                         1/1     Running   0          27h
kube-proxy-5ntm5                         1/1     Running   0          29h
kube-proxy-6pbrv                         1/1     Running   0          26h
kube-scheduler-node1.ztpt.com            1/1     Running   1          29h
kubernetes-dashboard-77fd78f978-wzqjq    1/1     Running   0          5m7s
4、配置外网访问
修改service配置,将type: ClusterIP改成NodePort
kubectl edit service  kubernetes-dashboard --namespace=kube-system
查看外网暴露端口
[root@node1 ~]# kubectl get service --namespace=kube-system
NAME                   TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)         AGE
kube-dns               ClusterIP   10.96.0.10       <none>        53/UDP,53/TCP   47h
kubernetes-dashboard   NodePort    10.101.221.220   <none>        443:32240/TCP   17h
5、创建dashboard admin-token
创建admin-token.yaml文件,文件内容如下:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: admin
  annotations:
    rbac.authorization.kubernetes.io/autoupdate: "true"
roleRef:
  kind: ClusterRole
  name: cluster-admin
  apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
  name: admin
  namespace: kube-system
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: admin
  namespace: kube-system
  labels:
    kubernetes.io/cluster-service: "true"
    addonmanager.kubernetes.io/mode: Reconcile
创建用户
kubectl create -f admin-token.yaml 
获取登陆token
kubectl describe secret/$(kubectl get secret -nkube-system |grep admin|awk '{print $1}') -nkube-system
6.通过浏览器登陆dashboard
https://节点IP:bashboard暴露端口
认证方式选择口令,输入刚才获取到的token,即可登陆成功。
进入后就会看到如下界面
image.png
image.png
上一篇下一篇

猜你喜欢

热点阅读