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

相关文章

Win11安装PostgreSQL数据库的两种方式详细步骤

《Win11安装PostgreSQL数据库的两种方式详细步骤》PostgreSQL是备受业界青睐的关系型数据库,尤其是在地理空间和移动领域,:本文主要介绍Win11安装PostgreSQL数据库的... 目录一、exe文件安装 (推荐)下载安装包1. 选择操作系统2. 跳转到EDB(PostgreSQL 的

Linux系统中卸载与安装JDK的详细教程

《Linux系统中卸载与安装JDK的详细教程》本文详细介绍了如何在Linux系统中通过Xshell和Xftp工具连接与传输文件,然后进行JDK的安装与卸载,安装步骤包括连接Linux、传输JDK安装包... 目录1、卸载1.1 linux删除自带的JDK1.2 Linux上卸载自己安装的JDK2、安装2.1

macOS无效Launchpad图标轻松删除的4 种实用方法

《macOS无效Launchpad图标轻松删除的4种实用方法》mac中不在appstore上下载的应用经常在删除后它的图标还残留在launchpad中,并且长按图标也不会出现删除符号,下面解决这个问... 在 MACOS 上,Launchpad(也就是「启动台」)是一个便捷的 App 启动工具。但有时候,应

Linux卸载自带jdk并安装新jdk版本的图文教程

《Linux卸载自带jdk并安装新jdk版本的图文教程》在Linux系统中,有时需要卸载预装的OpenJDK并安装特定版本的JDK,例如JDK1.8,所以本文给大家详细介绍了Linux卸载自带jdk并... 目录Ⅰ、卸载自带jdkⅡ、安装新版jdkⅠ、卸载自带jdk1、输入命令查看旧jdkrpm -qa

tomcat多实例部署的项目实践

《tomcat多实例部署的项目实践》Tomcat多实例是指在一台设备上运行多个Tomcat服务,这些Tomcat相互独立,本文主要介绍了tomcat多实例部署的项目实践,具有一定的参考价值,感兴趣的可... 目录1.创建项目目录,测试文China编程件2js.创建实例的安装目录3.准备实例的配置文件4.编辑实例的

MySQL Workbench 安装教程(保姆级)

《MySQLWorkbench安装教程(保姆级)》MySQLWorkbench是一款强大的数据库设计和管理工具,本文主要介绍了MySQLWorkbench安装教程,文中通过图文介绍的非常详细,对大... 目录前言:详细步骤:一、检查安装的数据库版本二、在官网下载对应的mysql Workbench版本,要是

SpringBoot配置Ollama实现本地部署DeepSeek

《SpringBoot配置Ollama实现本地部署DeepSeek》本文主要介绍了在本地环境中使用Ollama配置DeepSeek模型,并在IntelliJIDEA中创建一个Sprin... 目录前言详细步骤一、本地配置DeepSeek二、SpringBoot项目调用本地DeepSeek前言随着人工智能技

通过Docker Compose部署MySQL的详细教程

《通过DockerCompose部署MySQL的详细教程》DockerCompose作为Docker官方的容器编排工具,为MySQL数据库部署带来了显著优势,下面小编就来为大家详细介绍一... 目录一、docker Compose 部署 mysql 的优势二、环境准备与基础配置2.1 项目目录结构2.2 基

Linux安装MySQL的教程

《Linux安装MySQL的教程》:本文主要介绍Linux安装MySQL的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux安装mysql1.Mysql官网2.我的存放路径3.解压mysql文件到当前目录4.重命名一下5.创建mysql用户组和用户并修

CentOS 7部署主域名服务器 DNS的方法

《CentOS7部署主域名服务器DNS的方法》文章详细介绍了在CentOS7上部署主域名服务器DNS的步骤,包括安装BIND服务、配置DNS服务、添加域名区域、创建区域文件、配置反向解析、检查配置... 目录1. 安装 BIND 服务和工具2.  配置 BIND 服务3 . 添加你的域名区域配置4.创建区域