通过使用
KubeKey
可以快速搭建Kubernetes
的基础环境,以及安装KubeSphere环境
# 很重要,不执行会造成国内数据拉取不下来
export KKZONE=cn
# curl -sfL https://get-kk.kubesphere.io | VERSION=v1.2.1 sh -
curl -sfL https://get-kk.kubesphere.io | VERSION=v2.0.0 sh -
chmod +x kk
初始化本地主机
./kk init os
## 国内一定要执行这句,否则拉不下来镜像
export KKZONE=cn
## 只安装Kubernetes
./kk create cluster --with-kubernetes v1.21.5
## 安装Kubernetes和kubesphere
./kk create cluster --with-kubernetes v1.21.5 --with-kubesphere v3.2.1
## 国内一定要执行这句,否则拉不下来镜像
export KKZONE=cn
./kk create config
会的到config-sample.yaml
文件,修改内容如下
piVersion: kubekey.kubesphere.io/v1alpha1
kind: Cluster
metadata:
name: sample
spec:
hosts:
- {name: node1, address: 192.168.211.137, internalAddress:192.168.211.137, user: root, password: yourpassword}
roleGroups:
etcd:
- node1
master:
- node1
worker:
- node1
controlPlaneEndpoint:
domain: lb.kubesphere.local
address: ""
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
registry:
registryMirrors: []
insecureRegistries: []
addons: []
然后执行命令
export KKZONE=cn
./kk create cluster -f config-sample.yaml
等待集群安装完成即可。
1. 创建配置文件
参数示例
./kk create config [--with-kubernetes version] [--with-kubesphere version] [(-f | --file) path]
我们执行如下语句
./kk create config
可以在当前目录下生成config-sample.yaml
,打开可查看到如下内容(不安装kubesphere)
spec:
hosts:
- {name: master, address: 192.168.0.2, internalAddress: 192.168.0.2, user: ubuntu, password: Testing123}
- {name: node1, address: 192.168.0.3, internalAddress: 192.168.0.3, user: ubuntu, password: Testing123}
- {name: node2, address: 192.168.0.4, internalAddress: 192.168.0.4, user: ubuntu, password: Testing123}
roleGroups:
etcd:
- master
master:
- master
worker:
- node1
- node2
controlPlaneEndpoint:
domain: lb.kubesphere.local
address: ""
port: 6443
2. 初始化主机组
## 国内一定要执行这句,否则拉不下来镜像
export KKZONE=cn
./kk init os -f config-sample.yaml
3. 安装Kubernetes
## 国内一定要执行这句,否则拉不下来镜像
export KKZONE=cn
./kk create cluster -f config-sample.yaml
如果过安装包含kubesphere
,可以使用如下命令查看安装状态
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
./kk delete cluster
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: nginx
image: nginx:1.20
[1] https://kubesphere.com.cn/docs/installing-on-linux/introduction/multioverview/
[2] https://kubesphere.com.cn/docs/installing-on-linux/introduction/kubekey/