服务器配置
nameip
master192.168.57.61 
node1192.168.57.76 

master 安装需要2H4G 磁盘空间至少需要20G

node1 安装需要4H4G 磁盘空间至少需要50G

安装k8s环境依赖,在每台服务器执行以下命令

命令:yum install -y socat conntrack ebtables ipset ipvsadm

下载KubeKey工具

//导入环境变量
export KKZONE=cn
//下载kubekey
curl -sfL https://get-kk.kubesphere.io | sh -


这个环境变量决定下载的时候去哪里下,设置了cn之后就会去国内源里下载,比较快

关闭selinux,swap,防火墙

 使用KubeKey生成一个k8s集群启动文件模板k8s.yaml

./kk create config --with-kubernetes v1.22.1 -f k8s.yaml

修改k8s集群启动文件模板

apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: master, address: 192.168.57.61, internalAddress: 192.168.57.61, user: root, password: "chen"}
  - {name: node1, address: 192.168.57.76, internalAddress: 192.168.57.76, user: root, password: "chen"}
  roleGroups:
    etcd:
    - master
    control-plane: 
    - master
    worker:
    - master
    - node1
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers 
    # internalLoadbalancer: haproxy

    domain: lb.kubesphere.local
    address: ""
    port: 6443
  kubernetes:
    version: v1.22.1
    clusterName: cluster.local
    autoRenewCerts: true
    containerManager: docker
  etcd:
    type: kubekey
  network:
    plugin: calico
    kubePodsCIDR: 192.168.57.0/24
    kubeServiceCIDR: 192.168.0.0/24
    ## multus support. https://github.com/k8snetworkplumbingwg/multus-cni
    multusCNI:
      enabled: false
  registry:
    privateRegistry: ""
    namespaceOverride: ""
    registryMirrors: []
    insecureRegistries: []
  addons: []

重点关注下两个参数

    kubePodsCIDR: 192.168.57.0/24
    kubeServiceCIDR: 192.168.0.0/24 

kubeServiceCIDR 必须写x.x.0.0 不能写网段,不然网络插件就会出问题

安装K8S集群

./kk create cluster -f k8s.yaml

检查节点完成后会提示你 要不要开始安装

直接 yes即可

安装时间大概10多分钟(根据网络可能会慢或快)

验证k8s集群

安装完成执行

[root@master ~]# kubectl get nodes 
NAME     STATUS   ROLES                         AGE   VERSION
master   Ready    control-plane,master,worker   55m   v1.22.1
node1    Ready    worker                        55m   v1.22.1

两个节点的状态都 ready 就绪了

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐