K8s学习笔记-kubernetes安装

1、环境准备

安装docker,参考文章

https://blog.csdn.net/zhailunwen/article/details/102895823

systemctl stop firewalld

systemctl disable firewalld

setenforce 0

swapoff -a(echo "vm.swappiness = 0">> /etc/sysctl.conf)

如果swpoff报错已使用,先释放

sync
echo 3 > /proc/sys/vm/drop_caches

2、配置kube的yum源

vi /etc/yum.repos.d/kubernetes.rep

内容如下

[Kubernetes]
name=Kubernetes Repository
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0

3、安装

yum install -y kubelet kubeadm kubectl

可能报错

K8s学习笔记-kubernetes安装_第1张图片

出现上面错误先配置国内docker源

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 -y kubelet kubeadm kubectl

安装完成后启动kubelet服务

systemctl enable kubelet

systemctl start kubelet

 

4、下载kubernetes相关镜像

这一步我不管怎么配置yum源都失败,我就直接pull别的仓库下来,然后改标签了

首先查看需要的镜像kubeadm config images list

K8s学习笔记-kubernetes安装_第2张图片

然后在直接手动pull

docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.17.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5

后面直接更改标签

docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.17.2 k8s.gcr.io/kube-apiserver:v1.17.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.17.2 k8s.gcr.io/kube-controller-manager:v1.17.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.17.2 k8s.gcr.io/kube-scheduler:v1.17.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.4.3-0 k8s.gcr.io/etcd:3.4.3-0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.6.5 k8s.gcr.io/coredns:1.6.5

这样就ok了

K8s学习笔记-kubernetes安装_第3张图片

5、运行kubeadm init 安装master

kubeadm init 运行如下则成功

K8s学习笔记-kubernetes安装_第4张图片

后面跟着提示操作即可

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

安装cni网络插件

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

暂存

你可能感兴趣的:(Kubernetes,Linux)