KubeSphere入门到崩溃

KubeSphere 是在 Kubernetes 之上构建的以应用为中心企业级分布式容器平台,提供简单易用的操作界面以及向导式操作方式,在降低用户使用容器调度平台学习成本的同时,极大减轻开发、测试、运维的日常工作的复杂度,旨在解决 Kubernetes 本身存在的存储、网络、安全和易用性等痛点。除此之外,平台已经整合并优化了多个适用于容器场景的功能模块,以完整的解决方案帮助企业轻松应对敏捷开发与自动化运维、DevOps、微服务治理、灰度发布、多租户管理、工作负载和集群管理、监控告警、日志查询与收集、服务与网络、应用商店、镜像构建与镜像仓库管理和存储管理等多种业务场景。后续版本还将提供和支持多集群管理、大数据、人工智能等更为复杂的业务场景。
KubeSphere 从项目初始阶段就采用开源的方式来进行项目的良性发展,相关的项目源代码和文档都在 GitHub 可见。KubeSphere 支持部署和运行在包括公有云、私有云、VM、BM 和 Kubernetes 等任何基础设施之上,并且支持在线安装与离线安装,目前已在 阿里云、腾讯云、华为云、青云、AWS、Kubernetes 上进行过部署测试。
##KubeSphere入门到崩溃_第1张图片

一、系统用户图

KubeSphere入门到崩溃_第2张图片

二、中间件部署

应用部署需要关注的信息【应用部署三要素】
1、应用的部署方式
2、应用的数据挂载(数据,配置文件)
3、应用的可访问性
KubeSphere入门到崩溃_第3张图片

1、部署MySQL

1、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=ecJVNdEjcFuZY48E \
--restart=always \
-d mysql:5.7 

2、mysql配置示例

[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
lower_case_table_names=1
skip-name-resolve

3、mysql部署分析

KubeSphere入门到崩溃_第4张图片

4、原始部署方法

4.0 创建mysql配置文件
KubeSphere入门到崩溃_第5张图片
KubeSphere入门到崩溃_第6张图片

4.1、服务-创建-有状态服务器

KubeSphere入门到崩溃_第7张图片

4.2、创建有状态服务器名称 his-mysql-01

KubeSphere入门到崩溃_第8张图片

4.3、添加镜像

KubeSphere入门到崩溃_第9张图片

4.4、添加镜像 mysql:5.7,使用默认端口

KubeSphere入门到崩溃_第10张图片

4.5、添加环境变量,同步主机时区,选择对钩,下一步

KubeSphere入门到崩溃_第11张图片

4.6、添加持久卷声明模版

KubeSphere入门到崩溃_第12张图片

4.7、添加配置字典

KubeSphere入门到崩溃_第13张图片

4.8、存储和配置添加完毕-点击下一步

KubeSphere入门到崩溃_第14张图片

4.9、点击创建按钮

KubeSphere入门到崩溃_第15张图片

5.0、创建外部访问NodePort

KubeSphere入门到崩溃_第16张图片

创建名称
KubeSphere入门到崩溃_第17张图片

指定工作负载
KubeSphere入门到崩溃_第18张图片

添加端口
KubeSphere入门到崩溃_第19张图片

选择NodePort
KubeSphere入门到崩溃_第20张图片

6.0、测试连接mysql

查看his-mysql-01服务DNS
KubeSphere入门到崩溃_第21张图片
KubeSphere入门到崩溃_第22张图片

1、集群内部,直接通过应用的 【服务名.项目名】 直接访问
mysql -uroot -hhis-mysql-01.his -p

[root@k8s-master01 nfs_dir]# kubectl -n his exec -it his-mysql-01-v1-0 bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
root@his-mysql-v1-0:/# mysql -uroot -hhis-mysql-01.his -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

2、集群外部,
KubeSphere入门到崩溃_第23张图片

6.1、mysql登入失败


[root@k8s-master01 ~]# kubectl -n his get po
NAME                READY   STATUS    RESTARTS        AGE
his-mysql-01-v1-0   1/1     Running   1 (8m58s ago)   9m29s
[root@k8s-master01 ~]# 
#登入pod
[root@k8s-master01 ~]# kubectl -n his exec -it his-mysql-01-v1-0 bash

root@his-mysql-01-v1-0:/# mysql -u root -p

mysql> use mysql;

--修改root秘密
mysql> update user set authentication_string=passworD("ecJVNdEjcFuZY48E") where user='root';


--查看用户登入权限
mysql> SELECT HOST,USER from user;

--修改登入授权
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'ecJVNdEjcFuZY48E' WITH GRANT OPTION;

mysql> FLUSH PRIVILEGES;

mysql> exit

root@his-mysql-01-v1-0:/# exit


#登入pod
[root@k8s-master01 ~]# kubectl -n his exec -it his-mysql-01-v1-0 bash
kubectl exec [POD] [COMMAND] is DEPRECATED and will be removed in a future version. Use kubectl exec [POD] -- [COMMAND] instead.
root@his-mysql-01-v1-0:/# 

#内部pod登入测试
root@his-mysql-01-v1-0:/# mysql -uroot -hhis-mysql-01.his -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 


2、部署Redis

1、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

2、redis部署分析

KubeSphere入门到崩溃_第24张图片

界面添加创建启动命令
KubeSphere入门到崩溃_第25张图片

KubeSphere入门到崩溃_第26张图片

3、部署ElasticSearch

1、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

2、es部署分析

KubeSphere入门到崩溃_第27张图片

注意: 子路径挂载,配置修改后,k8s不会对其Pod内的相关配置文件进行热更新,需要自己重启Pod

[root@075a91de5863 config]# cat elasticsearch.yml

cluster.name: "docker-cluster"
network.host: 0.0.0.0

[root@075a91de5863 config]# cat 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

3、添加环境变量

KubeSphere入门到崩溃_第28张图片

4、添加子路径的个别子文件(jvm.options和elasticsearch.yml)

/usr/share/elasticsearch/config/elasticsearch.yml
KubeSphere入门到崩溃_第29张图片

KubeSphere入门到崩溃_第30张图片

/usr/share/elasticsearch/config/jvm.options
KubeSphere入门到崩溃_第31张图片

KubeSphere入门到崩溃_第32张图片

4、应用商店

可以使用 dev-zhao 登录,从应用商店部署

5、应用仓库

使用企业空间管理员(wuhan-boss)登录,设置应用仓库
学习Helm即可,去helm的应用市场添加一个仓库地址,比如:bitnami

charts.bitnami.com/bitnami

KubeSphere入门到崩溃_第33张图片

KubeSphere入门到崩溃_第34张图片

三、DevOps入门

1.Maven设置阿里云

KubeSphere入门到崩溃_第35张图片
配置字典-ks-devops-agent-编辑配置- MavenSetting( 下面新增)


    nexus-aliyun
    central
    Nexus aliyun
    http://maven.aliyun.com/nexus/content/groups/public

2.创建DevOps项目

2.1 平台管理-访问控制-企业空间-shenzhen-DevOps项目-创建

KubeSphere入门到崩溃_第36张图片

2.2 创建流水线 -下一步-创建

KubeSphere入门到崩溃_第37张图片

2.3编辑流水线-选择模版(我选择CI/CD)-下一步-创建-确定

KubeSphere入门到崩溃_第38张图片

2.4 流水线初步搭建

KubeSphere入门到崩溃_第39张图片

持续更新中…

参考网站:
【云原生Java架构师的第一课K8s+Docker+KubeSphere+DevOps】https://www.bilibili.com/video/BV13Q4y1C7hS?p=85&vd_source=2d34fd2352ae451c4f6d4cb20707e169

你可能感兴趣的:(k8s,kubernetes,云原生,容器)