准备工作
购买服务器,至少4核8g
关闭防火墙
[root@master ~]# systemctl status firewalld.service
# 如果输出
Unit firewalld.service could not be found.
# 拉取服务
[root@master ~]# yum install firewalld systemd -y
# 再次查看防火墙状态
[root@master ~]# systemctl status firewalld.service
# 关闭防火墙
root@master ~]# systemctl stop firewalld.service
# 设置开机自动关闭防火墙
systemctl disable firewalld.service
kubersphere单节点安装
kubersphere官网 kubesphere.io/zh/
ALL in one 教程 kubesphere.io/zh/docs/qui…
下载 KubeKey
export KKZONE=cn
curl -sfL https://get-kk.kubesphere.io | VERSION=v1.1.1 sh -
开始安装
命令模板
./kk create cluster [--with-kubernetes version] [--with-kubesphere version]
执行命令
./kk create cluster --with-kubernetes v1.20.4 --with-kubesphere v3.1.1
如果报错可能需要安装conntrack
yum install -y conntrack
如果看到这个界面,证明已经安装完成
#####################################################
Welcome to KubeSphere!
#####################################################
Console: http://10.140.167.4:30880 Account: admin Password: P@88w0rd
NOTES:
- After you log into the console, please check the monitoring status of service components in "Cluster Management". If any service is not ready, please wait patiently until all components are up and running.
- Please change the default password after login.
##################################################### kubesphere.io 2022-04-02 10:38:51 #####################################################
如果不小心把这个数据清除掉了也没关系,默认的用户名和密码都是一样的,不要使用内网ip登录哦,使用公网ip进行登录
http://139.198.9.89:30880/login Account: admin Password: P@88w0rd
#此外,如果想要卸载kubersphere,使用 ./kk delete cluster
使用集群部署的话,就根据集群部署的引导文件删除就可以了
安装后启用 DevOps
-
以
admin用户登录控制台,点击左上角的平台管理,选择集群管理。 -
点击 CRD,在搜索栏中输入
clusterconfiguration,点击搜索结果查看其详细页面。信息
定制资源定义(CRD)允许用户在不新增 API 服务器的情况下创建一种新的资源类型,用户可以像使用其他 Kubernetes 原生对象一样使用这些定制资源。
-
在自定义资源中,点击
ks-installer右侧的,选择编辑 YAML。
-
在该 YAML 文件中,搜索
devops,将enabled的false改为true。完成后,点击右下角的确定,保存配置。devops: enabled: true # 将“false”更改为“true”。 -
在 kubectl 中执行以下命令检查安装过程:
kubectl logs -n kubesphere-system $(kubectl get pod -n kubesphere-system -l app=ks-install -o jsonpath='{.items[0].metadata.name}') -f
创建企业空间
平台管理 > 访问控制 > 企业空间 > 创建企业空间
创建项目
进入企业空间 > 创建项目
服务部署
部署mysql服务 docker启动mysql服务命令
docker run -p 3306:3306 --name mysql-01 \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=root \
--restart=always \
-d mysql:5.7
创建配置文件
配置中心-配置
key:
pro-mysql
value:
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
创建存储卷
存储管理-存储卷
创建服务
挂载配置和存储卷
如果能看到这个,证明创建成功
# cat /etc/mysql/conf.d/my.cnf
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
init_connect='SET collation_connection = utf8mb4_unicode_ci'
init_connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
对于每个服务,在内容可以通过dns进行访问,dns组成为服务名+项目名
可以创建一个指定工作负载,实现外网访问
部署redis服务
# 相关配置先准备
# 创建配置文件
## 1、准备redis配置文件内容
mkdir -p /mydata/redis/conf && vim /mydata/redis/conf/redis.conf
##配置示例
appendonly yes
port 6379
bind 0.0.0.0
#docker启动redis
docker run -d -p 6379:6379 --restart=always \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /mydata/redis-01/data:/data \
--name redis-01 redis:6.2.5 \
redis-server /etc/redis/redis.conf
首先先创建配置文件
创建redis服务 注意需要配置启动命令
也可以在创建时指定存储卷
挂载配置文件
es容器部署
# 创建数据目录
mkdir -p /mydata/es-01 && chmod 777 -R /mydata/es-01
# 容器启动
docker run --restart=always -d -p 9200:9200 -p 9300:9300 \
-e "discovery.type=single-node" \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-v es-config:/usr/share/elasticsearch/config \
-v /mydata/es-01/data:/usr/share/elasticsearch/data \
--name es-01 \
elasticsearch:7.13.4
这个容器部署的特殊之处在于只会挂载容器内的目录下的部分配置文件到容器外
elasticsearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0
jvm.options
################################################################
##
## JVM configuration
##
################################################################
##
## WARNING: DO NOT EDIT THIS FILE. If you want to override the
## JVM options in this file, or set any additional options, you
## should create one or more files in the jvm.options.d
## directory containing your adjustments.
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/jvm-options.html
## for more information.
##
################################################################
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## The heap size is automatically configured by Elasticsearch
## based on the available memory in your system and the roles
## each node is configured to fulfill. If specifying heap is
## required, it should be done through a file in jvm.options.d,
## and the min and max should be set to the same value. For
## example, to set the heap to 4 GB, create a new file in the
## jvm.options.d directory containing these lines:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
## for more information
##
################################################################
################################################################
## Expert settings
################################################################
##
## All settings below here are considered expert settings. Do
## not adjust them unless you understand what you are doing. Do
## not edit them in this file; instead, create a new file in the
## jvm.options.d directory containing your adjustments.
##
################################################################
## GC configuration
8-13:-XX:+UseConcMarkSweepGC
8-13:-XX:CMSInitiatingOccupancyFraction=75
8-13:-XX:+UseCMSInitiatingOccupancyOnly
## G1GC Configuration
# NOTE: G1 GC is only supported on JDK version 10 or later
# to use G1GC, uncomment the next two lines and update the version on the
# following three lines to your version of the JDK
# 10-13:-XX:-UseConcMarkSweepGC
# 10-13:-XX:-UseCMSInitiatingOccupancyOnly
14-:-XX:+UseG1GC
## JVM temporary directory
-Djava.io.tmpdir=${ES_TMPDIR}
## heap dumps
# generate a heap dump when an allocation from the Java heap fails; heap dumps
# are created in the working directory of the JVM unless an alternative path is
# specified
-XX:+HeapDumpOnOutOfMemoryError
# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data
# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log
## JDK 8 GC logging
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m
# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
挂载子路径
配置企业仓库,可以一键部署应用
进入企业空间-应用管理-应用仓库
配置bitnami仓库
https://charts.bitnami.com/bitnami
创建应用即可一键部署
项目上云实战
开通阿里云“容器镜像服务(个人版)
-
- 创建一个名称空间(cc630)。(存储镜像)
- 推送镜像到阿里云镜像仓库
docker login --username=cc847417630 registry.cn-heyuan.aliyuncs.com
#把本地镜像,改名,成符合阿里云名字规范的镜像。
docker tag [ImageId] registry.cn-heyuan.aliyuncs.com/cc630/镜像名:[镜像版本号]
docker tag 95ddd7a353e0 registry.cn-heyuan.aliyuncs.com/cc630/test:1.0
docker push registry.cn-heyuan.aliyuncs.com/cc630/镜像名:[镜像版本号]
docker push registry.cn-heyuan.aliyuncs.com/cc630/test:1.0
# 先将jar包和Dockerfile上传到服务器
# 将服务打包成docker镜像
docker build -t test:1.0 .