kubeadm搭建k8s v1.10.13

栏目: 编程工具 · 发布时间: 7年前

内容简介:首先说下为什么选择这个版本,因为这个版本是目前k8s1.10分支中最稳定的版本,其次是k8s dashboard支持得比较好的版本,而且是比较成熟的版本,所以选择了这个版本首先我们初始化下新安装的系统,我有两台机器

kubeadm搭建k8s v1.10.13

首先说下为什么选择这个版本,因为这个版本是目前k8s1.10分支中最稳定的版本,其次是k8s dashboard支持得比较好的版本,而且是比较成熟的版本,所以选择了这个版本

系统初始化

首先我们初始化下新安装的系统,我有两台机器

  • 10.10.10.120
  • 10.10.10.121

下面的操作两台机器都要操作

使用我下面这个脚本关闭firewalld什么的

curl -O https://raw.githubusercontent.com/bboysoulcn/centos/master/centos.sh

**********************************
Powered by bboysoul
Email: bboysoulcn@gmail.com
Hostname: bboysoul-k8s-master
Virtualization is not supported
Cpu model: Common KVMprocessor
Memory: 3789 M
Swap:  0 M
Kernel version:  CentOS Linux release 7.6.1810 (Core)
**********************************
1) install_software    5) set_hostname	     9) install_ohmyzsh
2) install_python      6) close_selinux	    10) add_user
3) set_static_ip       7) install_docker    11) exit
4) close_firewalld     8) change_swap	    12) help:

选择第一项安装基础软件,选择第四项关闭firewalld,选择第五项设置主机名,我的主机名是下面两个

  • bboysoul-k8s-master
  • bboysoul-k8s-slave1

选择第六项关闭selinux,选择第七项安装docker,选择第九项安装oh my zsh

关闭swap

swapoff -a

之后修改 docker 的仓库地址,编辑下面这个文件

vim /etc/docker/daemon.json

加入

{
  "registry-mirrors": [
                        "https://docker.mirrors.ustc.edu.cn"
                        ]
}

重启docker

安装kubeadm kubelet kubectl

同样的两台机器都要操作

添加软件源

vim /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

安装

yum install kubeadm-1.10.13-0.x86_64 kubelet-1.10.13-0.x86_64 kubectl-1.10.13-0.x86_64

让kubelet开机启动

systemctl enable kubelet

启动kubelet

systemctl start kubelet

发现kubelet启动不起来

报错

"systemed" is different from docker cgroup driver: "cgroupfs"

于是

vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf

修改

Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=systemed"

为

Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"

另外一个节点也要这么做

启动master节点

输入下面的命令启动master节点

kubeadm init --kubernetes-version stable-1.10 --apiserver-advertise-address 10.10.10.120 --pod-network-cidr=10.244.0.0/16

报错

[ERROR SystemVerification]: unsupported docker version: 18.09.3

说docker版本不支持,直接忽略

kubeadm init --kubernetes-version stable-1.10 --apiserver-advertise-address 10.10.10.120 --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=all

最后显示

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
as root:

  kubeadm join 10.10.10.120:6443 --token xv3h2w.x1mwfesew7jcn07b --discovery-token-ca-cert-hash sha256:16fce397d457f1fcbdfc04031fbea686722dbf9c4a5b356a06ff2d3b955528d0

说明成功

添加work节点

直接使用下面命令在work节点添加就好

kubeadm join 10.10.10.120:6443 --token xv3h2w.x1mwfesew7jcn07b --discovery-token-ca-cert-hash sha256:16fce397d457f1fcbdfc04031fbea686722dbf9c4a5b356a06ff2d3b955528d0 --ignore-preflight-errors=all

之后在master节点执行

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

kubectl get node

你会发现两个节点都是没有ready的,kube-dns一直在pending状态,是因为没有安装flannel网络的缘故

➜  ~ kubectl get node
NAME                  STATUS     ROLES     AGE       VERSION
bboysoul-k8s-master   NotReady   master    12m       v1.10.13
bboysoul-k8s-slave1   NotReady   <none>    3m        v1.10.13

安装flannel网络

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml

完成之后等几分钟执行

kubectl get node

你就会发现所有的节点都已经ready了

创建用户

创建用户

vim ServiceAccount.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: bboysoul
  namespace: kube-system

给用户绑定权限

vim ClusterRoleBinding.yaml

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: bboysoul
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
- kind: ServiceAccount
  name: bboysoul
  namespace: kube-system

之后应用执行上面的操作

kubectl apply -f ServiceAccount.yaml

kubectl apply -f ClusterRoleBinding.yaml

接着查看用户的token

kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep bboysoul | awk '{print $1}')

安装dashboard

安装

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml

修改dashboard的service类型为nodeport

kubectl -n kube-system edit service kubernetes-dashboard

把spec下

type: ClusterIP

改为

type: NodePort

查看分配的端口

kubectl get svc -n kube-system

之后使用https访问

https://10.10.10.120:31930

接着我们使用上面创建的用户的token登录就好了

最后说几句

关于国内网络环境什么的,这个我就不说了,拉取镜像你可以在国内各个镜像源里面拉,实在不会可以问我,我因为是路由器上外网的,所以就不存在这些恶心的问题,还有k8s的更新实在是太快了,很久之前我就写了搭建1.12版本的,后来因为工作忙,一直没有出来,当我再想写的时候出了1.13,当我想完善1.13安装的时候,版本又更新了,无奈,找一个最稳定的版本玩玩算了。

欢迎关注Bboysoul的博客www.bboysoul.com

Have Fun


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

Modeling the Internet and the Web

Modeling the Internet and the Web

Pierre Baldi、Paolo Frasconi、Padhraic Smyth / Wiley / 2003-7-7 / USD 115.00

Modeling the Internet and the Web covers the most important aspects of modeling the Web using a modern mathematical and probabilistic treatment. It focuses on the information and application layers, a......一起来看看 《Modeling the Internet and the Web》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具