Kubernetes安装部署流程
Kubernetes 介绍
Kubernetes是当今最流⾏的开源容器管理平台,它就是⼤名⿍⿍的Google Borg的开源版本。Google在2014年推出了Kubernetes。
Kubernetes源于希腊语,意为舵⼿,K8S是⼀个简称,因为⾸尾字母中间正好有8个字母。基于容器技术,Kubernetes可以⽅便的进⾏集应⽤的部署、扩容、缩容、⾃愈机制、服务发现、负载均衡、⽇志、监控等功能,⼤⼤减少⽇常运维的⼯作量。
Kubernetes所有的操作都可以通过Kubernetes API来进⾏,通过API来操作Kubernetes中的对象,包括Pod、Service、Volume、Namespace等等。
Kubernetes 设计架构
安装前准备
1. ⼀台或多台机器,操作系统CentOS7.x86_x64
2. 硬件配置:2GB或更多RAM,2个CPU或更多CPU,硬盘30GB或更多
3. 集中所有机器之间⽹络互通
4. 可以访问外⽹,需要拉取镜像
5. 禁⽌swap分区
1.准备环境
分别在master、node1、node2(执⾏)
关闭防⽕墙
$ systemctl stop firewalld
$ systemctl disable firewalld
关闭swap
$ swapoff -a $ 临时
$ vim /etc/fstab $ 永久
添加主机名与IP对应关系
192.168.31.140 k8s-master
192.168.31.141 k8s-node1
192.168.31.142 k8s-node2
将桥连的IPv4流量传递到iptables的链中:
$ cat > /etc/sysctl.f << EOF
net.bridge.bridge.-nf-call-ip6tables = 1
net.bridge.bridge.-nf-call-iptables = 1
EOF
2.安装Docker
分别在master、node1、node2(安装docker)
$ wget mirrors.aliyun/docker-ce/linux/po -O /pos.po
$ yum -y install docker-ce-18.-3.el7
$ systemctl enable docker && systemctl start docker
$ docker --version
3.添加阿⾥云YUM软件源
分别在master、node1、node2(执⾏)
$ cat > /pos.po << EOF
[kubernetes]
name=Kubernetes
baseurl=mirrors.aliyun/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=mirrors.aliyun/kubernetes/yum/doc/yum-key.gpg
mirrors.aliyun/kubernetes/yum/doc/rpm-package-key.gpg
EOF
4.安装kubeadm、kubelet、kubectl
分别在master、node1、node2(执⾏)
$ yum -y install kubelet-1.15.0 kubeadm-1.15.0 kubectl-1.15.0
$ systemctl enable kubelet.service
部署kubernetes Master
1.在19
2.168.31.140(Master)执⾏,由于默认拉取的镜像⽂件地址是国内⽆法下载的,因此指定阿⾥云镜像地址。
$ kubeadm init \
--apiserver-advertise-address=192.168.31.140 \
--image-repository registry.aliyuncs/google_containers \
--kubernetes-version v1.15.0 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/f $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
2.下载l官⽅⽂件,现在国内下载不了该站点的⽂件,可以通过修改hosts⽂件的⽅法解决,到真实IP地址并添加到
hosts⽂件的最后⼀⾏。
$ 199.232.68.133 raw.githubusercontent >> /etc/hosts
$ kubectl apply -f
raw.githubusercontent/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/l
3.分别在master、node1、node2上拉取镜像flannel:v0.11.0-amd64
$ docker pull lizhenliang/flannel:v0.11.0-amd64
有时候会⽹速慢下载不下来,但别的机器有镜像时,可以在⼀台机器中复制镜像到别的机器上。
查看所有镜像⽂件
$ docker images
压缩镜像
$ docker save -o v0.11.0-flannel.tar quay.io/coreos/flannel
在另⼀台机器上解压镜像
docker load < v0.11.0-flannel.tar
安装flannel
$ kubectl apply -l
4.安装节点到master上,复制初始化中打印的命令并分别在node1和node2上执⾏
$ kubeadm join 192.168.31.140:6443 --token 78yk4x.yk07bitlne6z08uh --discovery-token-ca-cert-hash sha256:f3d660ab28b0278eb3679b7fb63fedd673d 5.当镜像拉取成功后会有如图所⽰的提⽰信息
6.执⾏命令可看到节点信息已准备就绪
$ kubectl get nodes
部署kubernetes-dashboard
1.下载UI镜像
$ docker pull  lizhenliang/kubernetes-dashboard-amd64:v1.10.1
2.修改kubernetes-dashboard.yaml配置
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    /licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and
# limitations under the License.
# Configuration to deploy release version of the Dashboard UI compatible with
# Kubernetes 1.8.
#
# Example usage: kubectl create -f <this_file>
# ------------------- Dashboard Secret ------------------- #
apiVersion: v1
kind: Secret
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard-certs
namespace: kube-system
type: Opaque
---
# ------------------- Dashboard Service Account ------------------- #
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
---
# ------------------- Dashboard Role & Role Binding ------------------- #
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: kubernetes-dashboard-minimal
namespace: kube-system
rules:
# Allow Dashboard to create 'kubernetes-dashboard-key-holder' secret.
- apiGroups: [""]
- apiGroups: [""]
resources: ["secrets"]
verbs: ["create"]
# Allow Dashboard to create 'kubernetes-dashboard-settings' config map.
-
apiGroups: [""]
resources: ["configmaps"]
verbs: ["create"]
# Allow Dashboard to get, update and delete Dashboard exclusive secrets.
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["kubernetes-dashboard-key-holder", "kubernetes-dashboard-certs"]  verbs: ["get", "update", "delete"]
# Allow Dashboard to get and update 'kubernetes-dashboard-settings' config map.
- apiGroups: [""]
resources: ["configmaps"]
resourceNames: ["kubernetes-dashboard-settings"]
verbs: ["get", "update"]
# Allow Dashboard to get metrics from heapster.
- apiGroups: [""]
resources: ["services"]
resourceNames: ["heapster"]
verbs: ["proxy"]
- apiGroups: [""]
resources: ["services/proxy"]
resourceNames: ["heapster", "http:heapster:", "https:heapster:"]
verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: kubernetes-dashboard-minimal
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: kubernetes-dashboard-minimal
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kube-system
google官方下载app---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: kubernetes-dashboard
subjects:
- kind: ServiceAccount
name: kubernetes-dashboard
namespace: kube-system
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
---
# ------------------- Dashboard Deployment ------------------- #
kind: Deployment
apiVersion: apps/v1beta2
metadata:
labels:
k8s-app: kubernetes-dashboard
name: kubernetes-dashboard
namespace: kube-system
spec:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。