K8S 搭建一套带Dashboard的kubernetes集群


K8S 搭建一套带Dashboard的kubernetes集群

文章插图
K8S
kubernetes(K8S)是什么Kubernetes(常简称为K8S)是用于自动部署、扩展和管理容器化(containerized)应用程序的开源系统 。系统由google设计并捐赠给Cloud Native Computing Foundation(今属linux基金会)来使用 。
它旨在提供“跨主机集群的自动部署、扩展以及运行应用程序容器的平台” 。它支持一系列容器工具, 包括Docker等 。我们可以将Docker看成Kubernetes内部使用的低级别组件 。
为什么要使用kubernetesDocker这个新兴的容器化技术当前应用越来越广,并且其从单机走向集群也称为必然,而云计算的蓬勃发展正在加速这一进程 。kubernetes作为当前普遍被业界广泛认可和看好的docker分布式系统解决方案,前景非常可观 。
使用Kubernetes可以做什么:
  • 自动化容器的部署和复制
  • 随时扩展或收缩容器规模
  • 将容器组织成组,并且提供容器间的负载均衡
  • 很容易地升级应用程序容器的新版本
  • 提供容器弹性,如果容器失效就替换它
部署环境准备机器信息
K8S 搭建一套带Dashboard的kubernetes集群

文章插图
机器信息
关闭防火墙及selinux
# systemctl stop firewalld# systemctl disable firewalld# setenforce 0修改hosts
172.17.0.218 k8sm-218172.17.0.219 k8s-219172.17.0.220 k8s-220增加网络转发
# cat <<EOF > /etc/sysctl.d/k8s.confnet.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1EOF# sysctl --system //使配置生效安装组件安装指定版本Docker
# wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo# yum install docker-ce-18.06.1.ce-3.el7 -y# systemctl start docker # systemctl enable docker 安装指定版本kubelet,kubeadm,kubectl
# cat <<EOF > /etc/yum.repos.d/kubernetes.repo[kubernetes]name=Kubernetesbaseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64enabled=1gpgcheck=1repo_gpgcheck=1gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpgEOF# yum install kubelet-1.13.3 -y# yum install kubeadm-1.13.3 -y# yum install kubectl-1.13.3 -y# systemctl enable kubelet 初始化master
# kubeadm init --kubernetes-version=v1.13.3 --apiserver-advertise-address=172.17.0.218 --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12参数含义:
--kubernetes-version:指定kubeadm版本;
--pod-network-cidr:指定pod所属网络
--image-repository 指定下载源
--service-cidr:指定service网段,负载均衡ip
--ignore-preflight-errors=Swap/all:忽略 swap/所有 报错
初始化成功结果
Your Kubernetes master has initialized successfully!To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/configYou should now deploy a pod network to the cluster.Run "kubectl Apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/You can now join any number of machines by running the following on each nodeas root: kubeadm join 172.17.0.218:6443 --token ai3bxc.zgq33i1sbdybhnci --discovery-token-ca-cert-hash sha256:20cb9ccc07e2612bc3b31bd7b5e8909bdbd3d293e7c7f4c18dbee6f62ea94788增加kubectl权限访问
此处为初始化成功输出的内容,复制即可
# mkdir -p $HOME/.kube# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config# sudo chown $(id -u):$(id -g) $HOME/.kube/config安装pod网络组件
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml增加node到集群里
// master初始化后的命令# kubeadm join 172.17.0.218:6443 --token ai3bxc.zgq33i1sbdybhnci --discovery-token-ca-cert-hash sha256:20cb9ccc07e2612bc3b31bd7b5e8909bdbd3d293e7c7f4c18dbee6f62ea94788master节点查看node状态
# kubectl get nodeNAME STATUS ROLES AGE VERSIONk8s-219 Ready <none> 112m v1.13.3k8s-220 Ready <none> 113m v1.13.3k8sm-218 Ready master 162m v1.13.3部署webui dashboard下载官方的yaml文件:
# wget https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml修改两个地方
第一个是修改镜像,kubernetes-dashboard.yaml配置文件112行
90 # ------------------- Dashboard Deployment ------------------- # 9192 kind: Deployment 93 apiVersion: apps/v1 94 metadata: 95 labels: 96 k8s-app: kubernetes-dashboard 97 name: kubernetes-dashboard 98 namespace: kube-system 99 spec:100 replicas: 1101 revisionHistoryLimit: 10102 selector:103 matchLabels:104 k8s-app: kubernetes-dashboard105 template:106 metadata:107 labels:108 k8s-app: kubernetes-dashboard109 spec:110 containers:111 - name: kubernetes-dashboard112 #image: k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1113 image: mirrorgooglecontainers/kubernetes-dashboard-amd64:v1.10.0114 ports:115 - containerPort: 8443116 protocol: TCP


推荐阅读