k8s集群安装教程 基于Kubesphere

忘忧 2021年11月15日 606次浏览

KubeSphere官网

服务器信息

nameip
master192.168.40.153
node1192.168.40.161
node2192.168.40.162

准备工作 执行下列代码,在每一台服务器上

yum update -y 
yum install -y chrony 
systemctl enable chronyd
systemctl start chronyd
timedatectl set-ntp true
timedatectl set-timezone Asia/Shanghai
chronyc activity -v
iptables -F
systemctl status firewalld
systemctl stop firewalld
systemctl disable firewalld
yum install openssl openssl-devel -y
yum install socat -y
yum install epel-release -y
yum install conntrack-tools -y

生成配置文件

export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | VERSION=v1.0.1 sh -
chmod +x kk
./kk create config --with-kubesphere v3.0.0
vim config-sample.yaml

这时在当前目录下就创建一个config-sample.yaml
我们使用vim 将配置文件修改为


apiVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
  name: sample
spec:
  hosts:
  - {name: master, address: 192.168.40.153, internalAddress: 192.168.40.153, user: root, password: '8'}
  - {name: node1, address: 192.168.40.161, internalAddress: 192.168.40.161, user: root, password: '8'}
  - {name: node2, address: 192.168.40.162, internalAddress: 192.168.40.162, user: root, password: '8'}
  roleGroups:
    etcd:
    - master
    master: 
    - master
    worker:
    - master
    - node1
    - node2
  controlPlaneEndpoint:
    domain: lb.kubesphere.local
    address: ""
    port: "6443"
  kubernetes:
    version: v1.17.9
    imageRepo: kubesphere
    clusterName: cluster.local
  network:
    plugin: calico
    kubePodsCIDR: 10.233.64.0/18
    kubeServiceCIDR: 10.233.0.0/18
  registry:
    registryMirrors: []
    insecureRegistries: []
  addons: []


---
apiVersion: installer.kubesphere.io/v1alpha1
kind: ClusterConfiguration
metadata:
  name: ks-installer
  namespace: kubesphere-system
  labels:
    version: v3.0.0

vim保存退出 :wq!

./kk create cluster -f config-sample.yaml //开始安装

整个过程大概20分钟

安装完成

#####################################################
###              Welcome to KubeSphere!           ###
#####################################################

Console: http://192.168.40.153:30880
Account: admin
Password: P@88w0rd

NOTES:
  1. After logging into the console, please check the
     monitoring status of service components in
     the "Cluster Management". If any service is not
     ready, please wait patiently until all components
     are ready.
  2. Please modify the default password after login.

#####################################################
https://kubesphere.io             20xx-xx-xx xx:xx:xx
#####################################################

管理员密码重置

admin密码太难输了,直接重置admin密码 将密码重置为123456

kubectl patch users admin -p '{"spec":{"password":"123456"}}' --type='merge' && kubectl annotate users admin iam.kubesphere.io/password-encrypted- 

启用 kubectl 自动补全

yum -y install epel-release
yum install bash-completion bash-completion-extras -y
locate bash_completion.sh
updatedb
source /etc/profile.d/bash_completion.sh
logout //登出后重新登录
echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl completion bash >/etc/bash_completion.d/kubectl