Linux安装单机版kubernetes

1、禁用swap 功能

关闭所有的交换分区,如果需要回收磁盘资源,则可以使用swapoff关闭交换分区释放磁盘空间。

swapoff -a

为什么需要关闭swap?

kubernetes的设计是将实例紧密包装到尽可能接近100%。 所有的部署应该与CPU /内存限制固定在一起。 所以如果调度程序发送一个pod到一台机器,它不应该使用交换。 设计者不想交换,因为它会减慢速度。

2、添加 yum 源k8s.repo

在/etc/yum.repos.d/新建文件k8s.repo

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

3、安装kubelet kubeadm kubectl

  • kubelet:运行在集群所有节点上,用于启动Pod和容器等对象的工具
  • kubeadm:用于初始化集群,启动集群命令工具
  • kubectl:用于和集群通信的命令行,通过kubectl可以部署和管理应用,查看各种资源,创建、删除和更新各种组件
yum install -y kubelet-1.21.0 kubeadm-1.21.0 kubectl-1.21.0

4、安装k8s相关镜像

官网镜像由于网络问题,无法拉取,使用https://hub.docker.com/r/myifeng/k8s.gcr.io_kube-controller-manager 拉取镜像后tag 为官方镜像即可使用:

docker tag myifeng/k8s.gcr.io_kube-apiserver:v1.21.0   k8s.gcr.io/kube-apiserver:v1.21.0
docker tag myifeng/k8s.gcr.io_kube-proxy:v1.21.0  k8s.gcr.io/kube-proxy:v1.21.0
docker tag myifeng/k8s.gcr.io_kube-controller-manager::v1.21.0  k8s.gcr.io/kube-controller-manager:v1.21.0
docker tag myifeng/k8s.gcr.io_kube-scheduler:v1.21.0   k8s.gcr.io/kube-scheduler:v1.21.0
docker tag myifeng/k8s.gcr.io_pause:3.4.1   k8s.gcr.io/pause:3.4.1
docker tag myifeng/k8s.gcr.io_coredns:1.8.0   k8s.gcr.io/coredns/coredns:v1.8.0
docker tag myifeng/k8s.gcr.io_etcd:3.4.13-0   k8s.gcr.io/etcd:3.4.13-0

5、启动 docker.service 和 kubelet.service

systemctl enable docker.service
systemctl start docker.service

systemctl enable kubelet.service
systemctl start kubelet.service

6、初始化集群

kubeadm init --kubernetes-version=v1.21.0

7、配置CA证书

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

8、安装flannel插件

wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml.
namespace/kube-flannel created
clusterrole.rbac.authorization.k8s.io/flannel configured
clusterrolebinding.rbac.authorization.k8s.io/flannel configured
serviceaccount/flannel created
configmap/kube-flannel-cfg created
daemonset.apps/kube-flannel-ds created

修改/etc/kubernetes/manifests/kube-controller-manager.yaml

spec:
  containers:
  - command:
    - kube-controller-manager
    - --authentication-kubeconfig=/etc/kubernetes/controller-manager.conf
    - --authorization-kubeconfig=/etc/kubernetes/controller-manager.conf
    - --bind-address=127.0.0.1
    - --client-ca-file=/etc/kubernetes/pki/ca.crt
    - --cluster-name=kubernetes
    - --cluster-signing-cert-file=/etc/kubernetes/pki/ca.crt
    - --cluster-signing-key-file=/etc/kubernetes/pki/ca.key
    - --controllers=*,bootstrapsigner,tokencleaner
    - --kubeconfig=/etc/kubernetes/controller-manager.conf
    - --leader-elect=true
    - --port=0
    - --requestheader-client-ca-file=/etc/kubernetes/pki/front-proxy-ca.crt
    - --root-ca-file=/etc/kubernetes/pki/ca.crt
    - --service-account-private-key-file=/etc/kubernetes/pki/sa.key
    - --use-service-account-credentials=true
      --allocate-node-cidrs=true    # 添加
      --cluster-cidr=10.244.0.0/16  # 添加 与kube-flannel.yml 中保持一致

查看node状态

kubectl get node -o wide
NAME                          STATUS   ROLES                  AGE   VERSION   INTERNAL-IP     EXTERNAL-IP   OS-IMAGE                                              KERNEL-VERSION                      CONTAINER-RUNTIME
docker-ce011166091186.na131   Ready    control-plane,master   67m   v1.21.0   11.166.91.186   <none>        Alibaba Group Enterprise Linux Server 7.2 (Paladin)   5.10.84-004.ali5000.alios7.x86_64   docker://18.9.9

参考文档:

1、https://www.cnblogs.com/effortsing/p/10014613.html

2、https://www.jianshu.com/p/a7dcb3d89944

3、https://blog.csdn.net/weixin_44602192/article/details/119379041

4、https://www.jianshu.com/p/d27141e18398

你可能感兴趣的:(#,kubenetes,kubernetes,docker,kubeadm,kubelet,kubectl)