centos7 用kubeadm安装 k8s v1.10.0
Posted windy-love
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7 用kubeadm安装 k8s v1.10.0相关的知识,希望对你有一定的参考价值。
前提:centos能访问互联网, centos已经安装docker-ce
1、禁用防火墙
systemctl stop firewalld
systemctl disable firewalld
2、禁用SELINUX
setenforce 0
vi /etc/selinux/config
设置SELINUX=disabled
3、设置路由
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p /etc/sysctl.d/k8s.conf
4、下载国内镜像到本地,并tag为k8s内镜像
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/kube-apiserver-amd64:v1.10.0
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/kube-scheduler-amd64:v1.10.0
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/kube-controller-manager-amd64:v1.10.0
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/kube-proxy-amd64:v1.10.0
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/k8s-dns-kube-dns-amd64:1.14.8
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/k8s-dns-dnsmasq-nanny-amd64:1.14.8
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/k8s-dns-sidecar-amd64:1.14.8
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/etcd-amd64:3.1.12
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/flannel:v0.10.0-amd64
docker pull registry.cn-shenzhen.aliyuncs.com/cp_m/pause-amd64:3.1
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/kube-apiserver-amd64:v1.10.0 k8s.gcr.io/kube-apiserver-amd64:v1.10.0
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/kube-scheduler-amd64:v1.10.0 k8s.gcr.io/kube-scheduler-amd64:v1.10.0
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/kube-controller-manager-amd64:v1.10.0 k8s.gcr.io/kube-controller-manager-amd64:v1.10.0
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/kube-proxy-amd64:v1.10.0 k8s.gcr.io/kube-proxy-amd64:v1.10.0
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/k8s-dns-kube-dns-amd64:1.14.8 k8s.gcr.io/k8s-dns-kube-dns-amd64:1.14.8
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/k8s-dns-dnsmasq-nanny-amd64:1.14.8 k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64:1.14.8
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/k8s-dns-sidecar-amd64:1.14.8 k8s.gcr.io/k8s-dns-sidecar-amd64:1.14.8
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/etcd-amd64:3.1.12 k8s.gcr.io/etcd-amd64:3.1.12
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/flannel:v0.10.0-amd64 quay.io/coreos/flannel:v0.10.0-amd64
docker tag registry.cn-shenzhen.aliyuncs.com/cp_m/pause-amd64:3.1 k8s.gcr.io/pause-amd64:3.1
5、设置k8s的国内源
cat <<EOF > /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
EOF
6、安装 kubelet、kubeadm、kubectl
yum makecache fast && yum install -y kubelet kubeadm kubectl
7、配置 kubelet
kubelet生成的配置文件将参数--cgroup-driver和docker的cgroup-driver必须一致
修改文件kubelet的配置文件/etc/systemd/system/kubelet.service.d/10-kubeadm.conf
将其中的KUBELET_CGROUP_ARGS参数更改成cgroupfs:
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"
Kubernetes从1.8开始要求关闭系统的 Swap ,可以通过 kubelet 的启动参数--fail-swap-on=false更改这个限制,在上面的配置文件中增加一项配置:
Environment="KUBELET_EXTRA_ARGS=--fail-swap-on=false"
最后,重新加载配置并启动kubelet
systemctl daemon-reload
systemctl enable kubelet && systemctl start kubelet
8、用kubeadm初始化
注意:如果是flannel网络--pod-network-cidr=10.244.0.0/16, 如果是Calico网络--pod-network-cidr=192.168.0.0/16
kubeadm init --kubernetes-version=v1.10.0 --pod-network-cidr=10.244.0.0/16
等待一段时间,如果出现下面信息,则表示初始化成功:
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/config
You 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 node
如果想要master也可以调度pod,则运行下面命令:
kubectl taint nodes --all node-role.kubernetes.io/master-
9、设置权限
要使kubectl适用于非root用户,请运行以下命令:
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
10、安装flannel网络
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml
11、查看POD节点
kubectl get pods --all-namespaces
所有节点,状态都是Running,则表示安装成功
参考网址:https://www.cnblogs.com/cp-miao/p/8891200.html
以上是关于centos7 用kubeadm安装 k8s v1.10.0的主要内容,如果未能解决你的问题,请参考以下文章