安装k8s的系统要求
- CPU / memory
Master: >=2U4G (4U16G is recommended)
Node: >=4U16G - Linux操作系统
基于 X86_64架构的各种Linux发行版本,Kernel版本要求在3.10及以上。
如:CentOS 7 、Red Hat Linux 7 - Docker
recommended: v1.12 and newer version - etcd
recommended: v3.0 and newer version
以CentOS为例,在安全的内部网络环境中可关闭防火墙服务,并建议禁用SELinux以便容器可读取主机文件系统
systemctl disable firewalld
systemctl stop firewalld
setenforce 0
# 或修改系统文件/etc/sysconfig/selinux,将SELINUX=enforcing修改成SELINUX=disabled,然后重启Linux
1. 使用kubeadm工具快速安装
若使用
yum install kubernetes
命令安装k8s,仍需修改各组件的启动参数,才能完成k8s集群的配置,过程复杂易出错。
v1.4版本开始引入命令行工具 kubeadm,致力于简化集群的安装和解决集群的高可用问题。
直到v1.6版本,此工具还不能用于生产环境,适合初学者学习使用。
kubeadm VS kops
(1) kubeadm需安装kubectl和kubelet,kops需预安装kubectl
(2) kubeadm只负责部署k8s在computers running Linux,不负责infrastructure orchestration,kops负责infrastructure orchestration和kubernetes orchestration
(3) kubeadm以容器化的方式运行kubernetes服务,kops以普通服务的方式运行kubernetes
(4) Integration with kubeadm, kops now uses kubeadm for some RBAC related functionality
1.1 安装kubeadm和相关工具
1.1.1 配置yum源
官方yum源:http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
某国内yum源:https://yumrepo.b0.upaiyun.com/centos/7/x86_64
阿里yum源:http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
- 配置文件/etc/yum.repos.d/kubernetes.repo的内容如下:
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
1.1.2 运行yum install
命令安装kubeadm和相关工具
You will install these packages on all of your machines:
- kubeadm: the command to bootstrap the cluster.
- kubelet: the component that runs on all of the machines in your cluster and does things like starting pods and containers.
- kubectl: the command line util to talk to your cluster.
yum install -y kubeadm-1.10.0-0.x86_64 kubectl-1.10.0-0.x86_64 kubelet-1.10.0-0.x86_64
1.1.3 启动docker服务和kubelet服务,并设置为开机启动
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet
1.2 下载kubernetes的相关镜像
# 手动pull镜像
docker pull warrior/pause-amd64:3.0
docker pull warrior/etcd-amd64:3.0.17
docker pull warrior/kube-apiserver-amd64:v1.6.0
docker pull warrior/kube-scheduler-amd64:v1.6.0
docker pull warrior/kube-controller-manager-amd64:v1.6.0
docker pull warrior/kube-proxy-amd64:v1.6.0
docker pull warrior/k8s-dns-kube-dns-amd64:1.14.1
docker pull warrior/k8s-dns-dnsmasq-nanny-amd64:1.14.1
docker pull warrior/k8s-dns-sidecar-amd64:1.14.1
docker pull gysan/exechealthz-amd64:1.2
docker pull gysan/dnsmasq-metrics-amd64:1.0
docker pull awa305/kube-discovery-amd64:1.0
# 更改镜像名,以供kubeadm使用
docker tag docker.io/warrior/pause-amd64:3.0 gcr.io/google_containers/pause-amd64:3.0
docker tag docker.io/warrior/etcd-amd64:3.0.17 gcr.io/google_containers/etcd-amd64:3.0.17
docker tag docker.io/warrior/kube-apiserver-amd64:v1.6.0 gcr.io/google_containers/kube-apiserver-amd64:v1.6.0
docker tag docker.io/warrior/kube-scheduler-amd64:v1.6.0 gcr.io/google_containers/kube-scheduler-amd64:v1.6.0
docker tag docker.io/warrior/kube-controller-manager-amd64:v1.6.0 gcr.io/google_containers/kube-controller-manager-amd64:v1.6.0
docker tag docker.io/warrior/kube-proxy-amd64:v1.6.0 gcr.io/google_containers/kube-proxy-amd64:v1.6.0
docker tag docker.io/warrior/k8s-dns-kube-dns-amd64:1.14.1 gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.1
docker tag docker.io/warrior/k8s-dns-dnsmasq-nanny-amd64:1.14.1 gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.1
docker tag docker.io/warrior/k8s-dns-sidecar-amd64:1.14.1 gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.1
docker tag docker.io/gysan/exechealthz-amd64:1.2 gcr.io/google_containers/exechealthz-amd64:1.2
docker tag docker.io/gysan/dnsmasq-metrics-amd64:1.0 gcr.io/google_containers/dnsmasq-metrics-amd64:1.0
docker tag docker.io/awa305/kube-discovery-amd64:1.0 gcr.io/google_containers/kube-discovery-amd64:1.0