Centos7安装Kubernetes1.11集群及Dashboard工具

bigdata 同时被 3 个专栏收录
10 篇文章 0 订阅
32 篇文章 0 订阅
10 篇文章 1 订阅

1. 测试节点

暂时一个Master节点,一个Node节点

192.168.1.148 Master
192.168.1.6 Node

建议首先清空iptables路由规则:

# (清理filter表规则,不加–t默认为filter表)
iptables -X && iptables -F && iptables -Z 
iptables -X -t nat && iptables -F -t nat && iptables -Z -t nat

2. Master及Node节点安装环境

# 关掉 selinux
setenforce  0 
sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
# 关掉防火墙 
systemctl stop firewalld
systemctl disable firewalld
# 关闭 swap
swapoff -a 
sed -i 's/.*swap.*/#&/' /etc/fstab
# 配置转发参数
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF

sysctl --system

# 设置国内 yum 源
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

# 安装一些必备的工具
yum install -y epel-release 
yum install -y net-tools wget vim  ntpdate

# 安装Docker
yum install -y docker
systemctl enable docker && systemctl start docker
systemctl enable docker.service

# 安装kubeadm、kubectl、kubelet
yum install -y kubelet kubeadm kubectl kubernetes-cni
systemctl enable kubelet && systemctl start kubelet

3. Master节点安装环境

  • 将以下shell写入脚本文件,并执行:
#!/bin/bash
images=(kube-proxy-amd64:v1.11.0 kube-scheduler-amd64:v1.11.0 kube-controller-manager-amd64:v1.11.0 kube-apiserver-amd64:v1.11.0
etcd-amd64:3.2.18 coredns:1.1.3 pause-amd64:3.1 kubernetes-dashboard-amd64:v1.8.3 k8s-dns-sidecar-amd64:1.14.9 k8s-dns-kube-dns-amd64:1.14.9
k8s-dns-dnsmasq-nanny-amd64:1.14.9 )
for imageName in ${images[@]} ; do
  docker pull registry.cn-hangzhou.aliyuncs.com/k8sth/$imageName
  docker tag registry.cn-hangzhou.aliyuncs.com/k8sth/$imageName k8s.gcr.io/$imageName
done

docker tag da86e6ba6ca1 k8s.gcr.io/pause:3.1

docker pull docker.io/mirrorgooglecontainers/k8s-dns-sidecar-amd64:1.14.9
docker tag docker.io/mirrorgooglecontainers/k8s-dns-sidecar-amd64:1.14.9 k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.9
docker rmi docker.io/mirrorgooglecontainers/k8s-dns-sidecar-amd64:1.14.9
docker tag docker.io/mirrorgooglecontainers/k8s-dns-kube-dns-amd64:1.14.9 k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.9
docker rmi docker.io/mirrorgooglecontainers/k8s-dns-kube-dns-amd64:1.14.9
docker pull docker.io/mirrorgooglecontainers/k8s-dns-dnsmasq-nanny-amd64:1.14.9
docker tag docker.io/mirrorgooglecontainers/k8s-dns-dnsmasq-nanny-amd64:1.14.9 k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.9
docker rmi docker.io/mirrorgooglecontainers/k8s-dns-dnsmasq-nanny-amd64:1.14.9

docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/flannel:v0.10.0-amd64
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/flannel:v0.10.0-amd64 quay.io/coreos/flannel:v0.10.0-amd64
  • 初始化Master节点
[root@ecs-master ~]# kubeadm init --kubernetes-version=v1.11.0 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=192.168.1.148
  • 安装Flannel网络
[root@ecs-master ~]# sysctl net.bridge.bridge-nf-call-iptables=1
net.bridge.bridge-nf-call-iptables = 1
[root@ecs-master ~]# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
clusterrole.rbac.authorization.k8s.io/flannel created
clusterrolebinding.rbac.authorization.k8s.io/flannel created
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.extensions/kube-flannel-ds created
  • 查看Master节点详情
[root@ecs-master ~]# export KUBECONFIG=/etc/kubernetes/admin.conf 
[root@ecs-master ~]# kubectl get nodes
NAME                        STATUS    ROLES     AGE       VERSION
ecs-master.novalocal   Ready     master    1h        v1.11.2
[root@ecs-master ~]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                                READY     STATUS    RESTARTS   AGE
kube-system   coredns-78fcdf6894-bwbwv                            1/1       Running   0          4m
kube-system   coredns-78fcdf6894-vtd2n                            1/1       Running   0          4m
kube-system   etcd-ecs-master.novalocal                      1/1       Running   0          3m
kube-system   kube-apiserver-ecs-master.novalocal            1/1       Running   0          3m
kube-system   kube-controller-manager-ecs-master.novalocal   1/1       Running   0          3m
kube-system   kube-flannel-ds-n4tvh                               1/1       Running   0          26s
kube-system   kube-proxy-gflxf                                    1/1       Running   0          4m
kube-system   kube-scheduler-ecs-master.novalocal            1/1       Running   0          3m

4. Node节点加入集群

  • 在node节点中安装docker相关服务
docker pull registry.cn-hangzhou.aliyuncs.com/k8sth/kube-proxy-amd64:v1.11.0
docker pull registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.1
docker tag registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.1 k8s.gcr.io/pause-amd64:3.1
docker tag registry.cn-hangzhou.aliyuncs.com/k8sth/kube-proxy-amd64:v1.11.0 k8s.gcr.io/kube-proxy-amd64:v1.11.0
docker tag registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.1 k8s.gcr.io/pause:3.1
  • 根据Master节点初始化时的提示加入集群(根据初始化Master时提示的实际情况输入token和hash)
[root@ecs-node ~]# kubeadm join 192.168.1.148:6443 --token wkj0bo.pzibll6rd9gyi5z8 --discovery-token-ca-cert-hash sha256:51985223a369a1f8c226f3ccdcf97f4ad5ff201a7c8c708e1636eea0739c0f05
  • 在master节点上查看集群当前状态
[root@ecs-master ~]# kubectl get nodes
NAME                        STATUS    ROLES     AGE       VERSION
ecs-master.novalocal   Ready     master    6m        v1.11.2
ecs-node.novalocal   Ready     <none>    1m        v1.11.2
[root@ecs-master ~]# kubectl get pods --all-namespaces
NAMESPACE     NAME                                                READY     STATUS    RESTARTS   AGE
kube-system   coredns-78fcdf6894-bwbwv                            1/1       Running   0          6m
kube-system   coredns-78fcdf6894-vtd2n                            1/1       Running   0          6m
kube-system   etcd-ecs-master.novalocal                      1/1       Running   0          5m
kube-system   kube-apiserver-ecs-master.novalocal            1/1       Running   0          5m
kube-system   kube-controller-manager-ecs-master.novalocal   1/1       Running   0          5m
kube-system   kube-flannel-ds-kcrnq                               1/1       Running   0          1m
kube-system   kube-flannel-ds-n4tvh                               1/1       Running   0          1m
kube-system   kube-proxy-gflxf                                    1/1       Running   0          6m
kube-system   kube-proxy-l8vzr                                    1/1       Running   0          1m
kube-system   kube-scheduler-ecs-master.novalocal            1/1       Running   0          5m

5. 安装Dashboard可视化工具

  • 使用第三方脚本(大神的github)
git clone https://github.com/cookcodeblog/k8s-deploy.git
cd k8s-deploy/k8s_dashboard/
chmod u+x *.sh
./deploy_k8s_dashboard.sh
  • 修改kubernetes-dashboard.yaml,不用代理方式访问WebUI

停止dashboard相关容器:

[root@ecs-master k8s_dashboard]#kubectl delete -f kubernetes-dashboard.yaml

修改kubernetes-dashboard.yaml内容:

kind: Service
apiVersion: v1
metadata:
  labels:
    k8s-app: kubernetes-dashboard
  name: kubernetes-dashboard
  namespace: kube-system
spec:
  # 添加Service的type为NodePort
  type: NodePort
  ports:
    - port: 443
      targetPort: 8443
      # (k8s只支持30000以上的端口)添加映射到host的端口
      nodePort: 30001
  selector:
    k8s-app: kubernetes-dashboard

重启dashboard服务:

[root@ecs-master k8s_dashboard]#kubectl apply -f kubernetes-dashboard.yaml
  • 通过浏览器访问https//<master-ip>:<nodePort>/

正常情况下会弹出以下页面:

这里写图片描述

可以看到这里支持两种方式登录:KubeConfig和token

这里的token就是在master初始化时或安装dashboard时提示的token字符串,如果忘记了可以这样获取:

[root@ecs-master ~]# kubectl -n kube-system describe $(kubectl -n kube-system get secret -n kube-system -o name | grep namespace) | grep token

而KubeConfig的制作也很简单,将master节点中的/etc/kubernetes/admin.conf的内容复制到一个新的文件,在这个新的文件内容最后加一项token的内容进去即可,如:

- name: kubernetes-admin
  user:
    client-certificate-data: 已有的xxxxxxxx
    client-key-data: 已有的xxxxxxx
    # 在这里加多一项
    token: 在这里粘贴你实际获得的token

将这个文件拷贝到你本地,在浏览器中选择Kubeconfig这一项,然后选择拷贝回来的kubeconfig文件,即可登录。

登录完成后主页如下所示:

这里写图片描述

参考资料:

http://www.cnblogs.com/cocowool/p/kubeadm_install_kubernetes.html
https://blog.csdn.net/nklinsirui/article/details/80806131

  • 0
    点赞
  • 0
    评论
  • 3
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值