KubeKey一键部署:轻松安装Kubernetes与KubeSphere

2024-02-23 07:52

本文主要是介绍KubeKey一键部署:轻松安装Kubernetes与KubeSphere,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

本文主要参考“在 Linux 上以 All-in-One 模式安装 KubeSphere”进行实践测试部署。

通过KubeKey工具实现Kubernetes(k8s)和KubeSphere的一键式安装,极大地简化了安装过程。用户无需手动预先安装Docker和Kubernetes,只需按照以下步骤操作:

  1. 关闭防火墙,确保安装环境的安全性。
  2. 关闭分区,确保系统的稳定性和兼容性。
  3. 安装依赖组件,为后续的KubeKey和Kubernetes安装做好准备。
  4. 下载KubeKey工具,这是实现一键安装的关键。
  5. 使用KubeKey的./kk命令创建Kubernetes和KubeSphere集群,整个安装过程将自动完成。

通过以上步骤,用户可以轻松完成Kubernetes和KubeSphere的安装,无需深入了解复杂的安装过程。

1. 准备资源

一台干净的服务器: Centos 7.6 系统,内核版本:3.10.0-1160.71.1.el7.x86_64。

IP

host

内存

CPU

10.8.3.246

master

8Gi

6cores

2. 准备网络

如果服务器已经可以上网,可忽略此步骤。

检查DNS:cat /etc/resolv.conf

若为空,则配置vi /etc/resolv.conf

插入内容:nameserver 61.139.2.69 (具体根据公司情况添加)

3. 环境准备

关闭防火墙、关闭分区、安装依赖组件。

[root@master home]#hostnamectl --static set-hostname master
[root@master home]#cat >> /etc/hosts << EOF 
10.8.3.246 master
EOF
[root@master home]### 关闭防火墙或者开放必要的[防火墙端口](https://v3-0.docs.kubesphere.io/docs/installing-on-linux/introduction/port-firewall/)
[root@master home]#systemctl disable firewalld
[root@master home]#systemctl stop firewalld
[root@master home]#systemctl status firewalld
[root@master home]### 查看并关闭swap分区
[root@master home]#swapoff -a
[root@master home]#echo "vm.swappiness=0" >> /etc/sysctl.conf
[root@master home]#sysctl -p /etc/sysctl.conf
net.ipv6.conf.eth0.accept_dad = 0
net.ipv6.conf.eth0.accept_ra = 1
net.ipv6.conf.eth0.accept_ra_defrtr = 1
net.ipv6.conf.eth0.accept_ra_rtr_pref = 1
net.ipv6.conf.eth0.accept_ra_rt_info_max_plen = 1
vm.swappiness = 0
[root@master home]#sed -i 's$/dev/mapper/centos-swap$#/dev/mapper/centos-swap$g' /etc/fstab
[root@master home]#sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux 
[root@master home]#sed -i "s/^SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config 
[root@master home]#sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/sysconfig/selinux 
[root@master home]#sed -i "s/^SELINUX=permissive/SELINUX=disabled/g" /etc/selinux/config
[root@master home]#free -m
totalusedfreeshared  buff/cache   available 
Mem:  32011 300 31168  16 542 31354
Swap:     0   0   0
[root@master home]### 查看Selinux状态
[root@master home]#getenforce
Disabled  
[root@master home]### 安装依赖组件  
[root@master home]#yum install -y ebtables socat ipset conntrack
Loaded plugins: fastestmirror
...........
Complete!

4. 使用kubekey一键安装

4.1. 下载kubekey

[root@master home]#yum install -y wget
Loaded plugins: fastestmirror
...........
Complete!
[root@master home]#export KKZONE=cn
[root@master home]#curl -sfL https://get-kk.kubesphere.io | sh -
[root@master home]#chmod +x kk  #如果无法下载?
#1.可以从https://github.com/kubesphere/kubekey/releases/tag/v3.0.13手动下载
#2.下载后解压:tar -zxvf kubekey-v3.0.13-linux-amd64.tar.gz
#3.授权chmod +x kk 

4.2. 方法1:高级安装(使用配置文件创建的集群)

参考:https://github.com/kubesphere/kubekey/blob/master/README_zh-CN.md#%E9%AB%98%E7%BA%A7%E7%94%A8%E6%B3%95

4.2.1. 创建配置文件

[root@master home]# ./kk create config --with-kubesphere
##需要修改上一条命令在当前目录生成的配置文件:config-sample.yaml,详见下文!

💡 Tips:./kk create config 后面带上--with-kubesphere,否则在安装时,只会安装k8s,不会安装KubeSphere。

4.2.2. 修改配置文件


apiVersion: kubekey.kubesphere.io/v1alpha2
kind: Cluster
metadata:name: sample
spec:hosts:- {name: master, address:10.8.3.246,port: 444, internalAddress: 10.8.3.246, user: root, password: "服务器密码"}#- {name: node2, address: 172.16.0.3, internalAddress: 172.16.0.3, user: ubuntu, password: "Qcloud@123"}roleGroups:etcd:- mastercontrol-plane: - masterworker:- master#- node2controlPlaneEndpoint:## Internal loadbalancer for apiservers # internalLoadbalancer: haproxydomain: lb.kubesphere.localaddress: ""port: 6443kubernetes:version: v1.23.10clusterName: cluster.localautoRenewCerts: truecontainerManager: dockeretcd:type: kubekeynetwork:plugin: calicokubePodsCIDR: 10.233.64.0/18kubeServiceCIDR: 10.233.0.0/18## multus support. https://github.com/k8snetworkplumbingwg/multus-cnimultusCNI:enabled: falseregistry:privateRegistry: ""namespaceOverride: ""registryMirrors: []insecureRegistries: []addons: []---
apiVersion: installer.kubesphere.io/v1alpha1
kind: ClusterConfiguration
metadata:name: ks-installernamespace: kubesphere-systemlabels:version: v3.4.1
spec:persistence:storageClass: ""authentication:jwtSecret: ""local_registry: ""# dev_tag: ""etcd:monitoring: falseendpointIps: localhostport: 2379tlsEnable: truecommon:core:console:enableMultiLogin: trueport: 30880type: NodePort# apiserver:#  resources: {}# controllerManager:#  resources: {}redis:enabled: falseenableHA: falsevolumeSize: 2Giopenldap:enabled: falsevolumeSize: 2Giminio:volumeSize: 20Gimonitoring:# type: externalendpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090GPUMonitoring:enabled: falsegpu:kinds:- resourceName: "nvidia.com/gpu"resourceType: "GPU"default: truees:# master:#   volumeSize: 4Gi#   replicas: 1#   resources: {}# data:#   volumeSize: 20Gi#   replicas: 1#   resources: {}enabled: falselogMaxAge: 7elkPrefix: logstashbasicAuth:enabled: falseusername: ""password: ""externalElasticsearchHost: ""externalElasticsearchPort: ""opensearch:# master:#   volumeSize: 4Gi#   replicas: 1#   resources: {}# data:#   volumeSize: 20Gi#   replicas: 1#   resources: {}enabled: truelogMaxAge: 7opensearchPrefix: whizardbasicAuth:enabled: trueusername: "admin"password: "admin"externalOpensearchHost: ""externalOpensearchPort: ""dashboard:enabled: falsealerting:enabled: false# thanosruler:#   replicas: 1#   resources: {}auditing:enabled: false# operator:#   resources: {}# webhook:#   resources: {}devops:enabled: falsejenkinsCpuReq: 0.5jenkinsCpuLim: 1jenkinsMemoryReq: 4GijenkinsMemoryLim: 4GijenkinsVolumeSize: 16Gievents:enabled: false# operator:#   resources: {}# exporter:#   resources: {}ruler:enabled: truereplicas: 2#   resources: {}logging:enabled: falselogsidecar:enabled: truereplicas: 2# resources: {}metrics_server:enabled: falsemonitoring:storageClass: ""node_exporter:port: 9100# resources: {}# kube_rbac_proxy:#   resources: {}# kube_state_metrics:#   resources: {}# prometheus:#   replicas: 1#   volumeSize: 20Gi#   resources: {}#   operator:#     resources: {}# alertmanager:#   replicas: 1#   resources: {}# notification_manager:#   resources: {}#   operator:#     resources: {}#   proxy:#     resources: {}gpu:nvidia_dcgm_exporter:enabled: false# resources: {}multicluster:clusterRole: nonenetwork:networkpolicy:enabled: falseippool:type: nonetopology:type: noneopenpitrix:store:enabled: falseservicemesh:enabled: falseistio:components:ingressGateways:- name: istio-ingressgatewayenabled: falsecni:enabled: falseedgeruntime:enabled: falsekubeedge:enabled: falsecloudCore:cloudHub:advertiseAddress:- ""service:cloudhubNodePort: "30000"cloudhubQuicNodePort: "30001"cloudhubHttpsNodePort: "30002"cloudstreamNodePort: "30003"tunnelNodePort: "30004"# resources: {}# hostNetWork: falseiptables-manager:enabled: truemode: "external"# resources: {}# edgeService:#   resources: {}gatekeeper:enabled: false# controller_manager:#   resources: {}# audit:#   resources: {}terminal:timeout: 600

4.2.3. 执行安装

##通过指定配置文件来创建集群
[root@master home]# ./kk create cluster -f config-sample.yaml
##等待完成即可!

4.3. 方法2:快速入门(all-in-one)

参考:在 Linux 上以 All-in-One 模式安装 KubeSphere

[root@master home]# ./kk create cluster --with-kubernetes v1.22.12 --with-kubesphere v3.4.1
#等待完成即可!

5. 验证安装结果

5.1. 等待安装并最终看到如下日志输出

#####################################################
###              Welcome to KubeSphere!           ###
#####################################################Console: http://10.8.3.246:30880
Account: admin
Password: P@88w0rd
NOTES:1. After you log into the console, please check themonitoring status of service components in"Cluster Management". If any service is notready, please wait patiently until all components are up and running.2. Please change the default password after login.#####################################################
https://kubesphere.io             2024-02-21 03:06:10
#####################################################
03:06:11 EST success: [master]
03:06:11 EST Pipeline[CreateClusterPipeline] execute successfully
Installation is complete.Please check the result using the command:kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f

5.2. 命令查看安装结果

 kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l 'app in (ks-install, ks-installer)' -o jsonpath='{.items[0].metadata.name}') -f

5.3. 浏览器访问

http://10.8.3.246:30880/

Account: admin

Password: P@88w0rd

6. 部署一个nginx

7. 卸载

#如果是使用高级模式安装的 KubeSphere(使用配置文件创建的),则使用以下命令卸载:
./kk delete cluster -f config-sample.yaml#如果是普通的,直接使用以下命令卸载:
./kk delete cluster

8. 问题

8.1. 还需要单独安装Docker吗?

KubeKey 会默认安装最新版本的 Docker。当然,也可以在创建集群前手动安装 Docker 或其他容器运行时。

上文安装创建过程中可以看到,默认已经下载并安装docker。

8.2. 使用方法2时,执行./kk create时报错?

错误信息:

21:54:16 EST [GreetingsModule] Greetings

21:54:16 EST failed: [node1]

error: Pipeline[CreateClusterPipeline] execute failed: Module[GreetingsModule] exec failed:failed: [node1] failed to connect to 10.8.3.246: could not establish connection to 10.8.3.246:22: dial tcp 10.8.3.246:22: connect: connection refused

原因:

kubekey默认用22端口!

而当前你的服务器ssh不是22端口,而是444或其他端口(看看远程服务器用的什么端口)!

解决办法:

方法1:改ssh端口,vi /etc/ssh/sshd_config改成22端口,重启ssh:systemctl restart sshd,再重试方法2。

法2:使用上文方法1:高级安装(使用配置文件创建的集群)。

9. 参考文献

官网地址:在 Linux 上以 All-in-One 模式安装 KubeSphere

github:https://github.com/kubesphere/kubekey

这篇关于KubeKey一键部署:轻松安装Kubernetes与KubeSphere的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/737971

相关文章

win10安装及配置Gradle全过程

《win10安装及配置Gradle全过程》本文详细介绍了Gradle的下载、安装、环境变量配置以及如何修改本地仓库位置,通过这些步骤,用户可以成功安装并配置Gradle,以便进行项目构建... 目录一、Gradle下载1.1、Gradle下载地址1.2、Gradle下载步骤二、Gradle安装步骤2.1、安

Nginx分布式部署流程分析

《Nginx分布式部署流程分析》文章介绍Nginx在分布式部署中的反向代理和负载均衡作用,用于分发请求、减轻服务器压力及解决session共享问题,涵盖配置方法、策略及Java项目应用,并提及分布式事... 目录分布式部署NginxJava中的代理代理分为正向代理和反向代理正向代理反向代理Nginx应用场景

python依赖管理工具UV的安装和使用教程

《python依赖管理工具UV的安装和使用教程》UV是一个用Rust编写的Python包安装和依赖管理工具,比传统工具(如pip)有着更快、更高效的体验,:本文主要介绍python依赖管理工具UV... 目录前言一、命令安装uv二、手动编译安装2.1在archlinux安装uv的依赖工具2.2从github

Java轻松实现PDF转换为PDF/A的示例代码

《Java轻松实现PDF转换为PDF/A的示例代码》本文将深入探讨Java环境下,如何利用专业工具将PDF转换为PDF/A格式,为数字文档的永续保存提供可靠方案,文中的示例代码讲解详细,感兴趣的小伙伴... 目录为什么需要将PDF转换为PDF/A使用Spire.PDF for Java进行转换前的准备通过

JDK8(Java Development kit)的安装与配置全过程

《JDK8(JavaDevelopmentkit)的安装与配置全过程》文章简要介绍了Java的核心特点(如跨平台、JVM机制)及JDK/JRE的区别,重点讲解了如何通过配置环境变量(PATH和JA... 目录Java特点JDKJREJDK的下载,安装配置环境变量总结Java特点说起 Java,大家肯定都

linux部署NFS和autofs自动挂载实现过程

《linux部署NFS和autofs自动挂载实现过程》文章介绍了NFS(网络文件系统)和Autofs的原理与配置,NFS通过RPC实现跨系统文件共享,需配置/etc/exports和nfs.conf,... 目录(一)NFS1. 什么是NFS2.NFS守护进程3.RPC服务4. 原理5. 部署5.1安装NF

PHP轻松处理千万行数据的方法详解

《PHP轻松处理千万行数据的方法详解》说到处理大数据集,PHP通常不是第一个想到的语言,但如果你曾经需要处理数百万行数据而不让服务器崩溃或内存耗尽,你就会知道PHP用对了工具有多强大,下面小编就... 目录问题的本质php 中的数据流处理:为什么必不可少生成器:内存高效的迭代方式流量控制:避免系统过载一次性

通过Docker容器部署Python环境的全流程

《通过Docker容器部署Python环境的全流程》在现代化开发流程中,Docker因其轻量化、环境隔离和跨平台一致性的特性,已成为部署Python应用的标准工具,本文将详细演示如何通过Docker容... 目录引言一、docker与python的协同优势二、核心步骤详解三、进阶配置技巧四、生产环境最佳实践

Nginx部署HTTP/3的实现步骤

《Nginx部署HTTP/3的实现步骤》本文介绍了在Nginx中部署HTTP/3的详细步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录前提条件第一步:安装必要的依赖库第二步:获取并构建 BoringSSL第三步:获取 Nginx

C#实现一键批量合并PDF文档

《C#实现一键批量合并PDF文档》这篇文章主要为大家详细介绍了如何使用C#实现一键批量合并PDF文档功能,文中的示例代码简洁易懂,感兴趣的小伙伴可以跟随小编一起学习一下... 目录前言效果展示功能实现1、添加文件2、文件分组(书签)3、定义页码范围4、自定义显示5、定义页面尺寸6、PDF批量合并7、其他方法