使用 KubeKey 部署 KubeSphere 和 Kubernetes

docker  

安装Docker

sudo yum remove docker*  
sudo yum install -y yum-utils

#配置docker的yum地址
sudo yum-config-manager \  
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

# 安装依赖
yum install ipset socat chrony -y

#ceph client ceph支持动态扩容,nfs不再支持
yum -y install ceph-common

# 低版的centos可以升级一下kernel
yum update kernel 

#安装指定版本
sudo yum install -y docker-ce-20.10.14 docker-ce-cli-20.10.14 containerd.io-1.5.11

#    启动&开机启动docker
systemctl enable docker --now

# docker加速配置
sudo mkdir -p /etc/docker  
sudo tee /etc/docker/daemon.json <<-'EOF'  
{
  "registry-mirrors": ["https://xet0ja6w.mirror.aliyuncs.com"]
}
EOF  
sudo systemctl daemon-reload  
sudo systemctl restart docker  

环境初始化

  • 基本环境
    每个机器使用内网ip互通
    每个机器配置自己的hostname,不能用localhost
#设置每个机器自己的hostname(三台主机)
hostnamectl set-hostname k8s-master-001  
hostnamectl set-hostname k8s-node-001  
hostnamectl set-hostname k8s-node-002

# 将 SELinux 设置为 permissive 模式(相当于将其禁用)
sudo setenforce 0  
sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

#关闭swap
swapoff -a  
sed -ri 's/.*swap.*/#&/' /etc/fstab

#允许 iptables 检查桥接流量
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf  
br_netfilter  
EOF

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf  
net.bridge.bridge-nf-call-ip6tables = 1  
net.bridge.bridge-nf-call-iptables = 1  
EOF  
sudo sysctl --system  

KubeKey 部署 KubeSphere 和 Kubernetes

  • 如果访问github受限
export KKZONE=cn  
  • 下载kubkey
curl -sfL https://get-kk.kubesphere.io | VERSION=v2.0.0 sh -  
  • 添加可执行权限
chmod +x kk  
  • 创建包含默认配置的示例配置文件
./kk create config --with-kubesphere v3.2.1 --with-kubernetes v1.21.5
  • 配置参考
apiVersion: kubekey.kubesphere.io/v1alpha2  
kind: Cluster  
metadata:  
  name: sample
spec:  
  hosts:
  - {name: k8s-master-001, address: 10.3.100.66, internalAddress: 10.3.100.66, user: root, password: "xxx,."}
  - {name: k8s-node-001, address: 10.3.100.67, internalAddress: 10.3.100.67, user: root, password: "xxx,."}
  - {name: k8s-node-002, address: 10.3.100.68, internalAddress: 10.3.100.68, user: root, password: "xxx,."}
  roleGroups:
    master:
    - k8s-master-001
    - k8s-node-001
    etcd:
    - k8s-node-001
    - k8s-node-002
    control-plane: 
    - k8s-node-001
    - k8s-node-002
    worker:
    - k8s-node-002
    - k8s-node-002
  controlPlaneEndpoint:
    ## Internal loadbalancer for apiservers 
    # internalLoadbalancer: haproxy

    domain: lb.kubesphere.local
    address: "10.3.100.66"
    port: 6443
  kubernetes:
    version: v1.21.5
    clusterName: cluster.local
  network:
    plugin: calico
    kubePodsCIDR: 10.233.64.0/18
    kubeServiceCIDR: 10.233.0.0/18
    ## multus support. https://github.com/k8snetworkplumbingwg/multus-cni
    multusCNI:
      enabled: false
  registry:
    plainHTTP: false
    privateRegistry: ""
    namespaceOverride: ""
    registryMirrors: []
    insecureRegistries: []
  addons: []



---
apiVersion: installer.kubesphere.io/v1alpha1  
kind: ClusterConfiguration  
metadata:  
  name: ks-installer
  namespace: kubesphere-system
  labels:
    version: v3.2.1
spec:  
  persistence:
    storageClass: ""
  authentication:
    jwtSecret: ""
  local_registry: ""
  namespace_override: ""
  # dev_tag: ""
  etcd:
    monitoring: true
    endpointIps: localhost
    port: 2379
    tlsEnable: true
  common:
    core:
      console:
        enableMultiLogin: true
        port: 30880
        type: NodePort
    # apiserver:
    #  resources: {}
    # controllerManager:
    #  resources: {}
    redis:
      enabled: true
      volumeSize: 2Gi
    openldap:
      enabled: true
      volumeSize: 2Gi
    minio:
      volumeSize: 20Gi
    monitoring:
      # type: external
      endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090
      GPUMonitoring:
        enabled: false
    gpu:
      kinds:         
      - resourceName: "nvidia.com/gpu"
        resourceType: "GPU"
        default: true
    es:
      # master:
      #   volumeSize: 4Gi
      #   replicas: 1
      #   resources: {}
      # data:
      #   volumeSize: 20Gi
      #   replicas: 1
      #   resources: {}
      logMaxAge: 7
      elkPrefix: logstash
      basicAuth:
        enabled: false
        username: ""
        password: ""
      externalElasticsearchHost: ""
      externalElasticsearchPort: ""
  alerting:
    enabled: true
    # thanosruler:
    #   replicas: 1
    #   resources: {}
  auditing:
    enabled: true
    # operator:
    #   resources: {}
    # webhook:
    #   resources: {}
  devops:
    enabled: true
    jenkinsMemoryLim: 2Gi
    jenkinsMemoryReq: 1500Mi
    jenkinsVolumeSize: 8Gi
    jenkinsJavaOpts_Xms: 512m
    jenkinsJavaOpts_Xmx: 512m
    jenkinsJavaOpts_MaxRAM: 2g
  events:
    enabled: true
    # operator:
    #   resources: {}
    # exporter:
    #   resources: {}
    # ruler:
    #   enabled: true
    #   replicas: 2
    #   resources: {}
  logging:
    enabled: true
    containerruntime: docker
    logsidecar:
      enabled: true
      replicas: 2
      # resources: {}
  metrics_server:
    enabled: false
  monitoring:
    storageClass: ""
    # kube_rbac_proxy:
    #   resources: {}
    # kube_state_metrics:
    #   resources: {}
    # prometheus:
    #   replicas: 1
    #   volumeSize: 20Gi
    #   resources: {}
    #   operator:
    #     resources: {}
    #   adapter:
    #     resources: {}
    # node_exporter:
    #   resources: {}
    # alertmanager:
    #   replicas: 1
    #   resources: {}
    # notification_manager:
    #   resources: {}
    #   operator:
    #     resources: {}
    #   proxy:
    #     resources: {}
    gpu:
      nvidia_dcgm_exporter:
        enabled: false
        # resources: {}
  multicluster:
    clusterRole: none 
  network:
    networkpolicy:
      enabled: true
    ippool:
      type: none
    topology:
      type: none
  openpitrix:
    store:
      enabled: true
  servicemesh:
    enabled: false
  kubeedge:
    enabled: false   
    cloudCore:
      nodeSelector: {"node-role.kubernetes.io/worker": ""}
      tolerations: []
      cloudhubPort: "10000"
      cloudhubQuicPort: "10001"
      cloudhubHttpsPort: "10002"
      cloudstreamPort: "10003"
      tunnelPort: "10004"
      cloudHub:
        advertiseAddress:
          - ""
        nodeLimit: "100"
      service:
        cloudhubNodePort: "30000"
        cloudhubQuicNodePort: "30001"
        cloudhubHttpsNodePort: "30002"
        cloudstreamNodePort: "30003"
        tunnelNodePort: "30004"
    edgeWatcher:
      nodeSelector: {"node-role.kubernetes.io/worker": ""}
      tolerations: []
      edgeWatcherAgent:
        nodeSelector: {"node-role.kubernetes.io/worker": ""}
        tolerations: []
  • 开始安装
./kk create cluster -f config-sample.yaml
  • 有时因为网络原因可能会失败,删除重新部署即可
./kk delete cluster -f config-sample.yaml
  • 验证安装(当提示等待安装完成时,使用此命令查看安装进度)
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f