|
|
|
@ -793,35 +793,323 @@ https://blog.csdn.net/nuptaxin/article/details/124008353
|
|
|
|
|
|
|
|
|
|
### 七、其它软件安装
|
|
|
|
|
|
|
|
|
|
k8s集群部署mysql完整过程记录
|
|
|
|
|
#### $7.1$ 部署$mysql$
|
|
|
|
|
|
|
|
|
|
https://www.cnblogs.com/blayn/p/16037199.html
|
|
|
|
|
> https://www.cnblogs.com/blayn/p/16037199.html
|
|
|
|
|
|
|
|
|
|
在$k8s$集群中挂载$MySQL$数据卷 需要安装一个$NFS$。
|
|
|
|
|
|
|
|
|
|
在 **主节点** 安装$NFS$
|
|
|
|
|
|
|
|
|
|
K8S用yaml资源清单部署redis数据库,数据持久化保存
|
|
|
|
|
```shell
|
|
|
|
|
yum install -y nfs-utils rpcbind
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
在 **主节点** 创建目录
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
mkdir -p /nfs
|
|
|
|
|
chmod 777 /nfs
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
更改归属组与用户
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
#chown -R nfsnobody:nfsnobody /nfs
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
配置共享目录
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
echo "/nfs *(insecure,rw,sync,no_root_squash)" > /etc/exports
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
创建$mysql$共享目录
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
mkdir -p /nfs/mysql
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
https://devpress.csdn.net/k8s/66c9a10413e4054e7e7d4f79.html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
启动服务+设置开启启动
|
|
|
|
|
|
|
|
|
|
K8s - 安装部署MongoDB数据库教程1(单实例)
|
|
|
|
|
```shell
|
|
|
|
|
systemctl enable --now nfs-server rpcbind
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
检查
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
[root@k8s-master openresty]# exportfs
|
|
|
|
|
showmount -e 10.10.14.200
|
|
|
|
|
/nfs <world>
|
|
|
|
|
Export list for 10.10.14.200:
|
|
|
|
|
/nfs *
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
https://www.cnblogs.com/gaoyanbing/p/17694272.html
|
|
|
|
|
通过
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
mkdir /data/mysql/data -p
|
|
|
|
|
mkdir /data/mysql/logs -p
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
k8s部署单点的minio集群
|
|
|
|
|
|
|
|
|
|
https://blog.csdn.net/baidu_35848778/article/details/131436354
|
|
|
|
|
**创建$MySQL$ $Deployment$**
|
|
|
|
|
|
|
|
|
|
编写一个 `mysql.yaml` 配置文件
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
apiVersion: apps/v1 # apiserver的版本
|
|
|
|
|
kind: Deployment # 副本控制器deployment,管理pod和RS
|
|
|
|
|
metadata:
|
|
|
|
|
name: mysql # deployment的名称,全局唯一
|
|
|
|
|
namespace: default # deployment所在的命名空间
|
|
|
|
|
labels:
|
|
|
|
|
app: mysql
|
|
|
|
|
spec:
|
|
|
|
|
replicas: 1 # Pod副本期待数量
|
|
|
|
|
selector:
|
|
|
|
|
matchLabels: # 定义RS的标签
|
|
|
|
|
app: mysql # 符合目标的Pod拥有此标签
|
|
|
|
|
strategy: # 定义升级的策略
|
|
|
|
|
type: RollingUpdate # 滚动升级,逐步替换的策略
|
|
|
|
|
template: # 根据此模板创建Pod的副本(实例)
|
|
|
|
|
metadata:
|
|
|
|
|
labels:
|
|
|
|
|
app: mysql # Pod副本的标签,对应RS的Selector
|
|
|
|
|
spec:
|
|
|
|
|
nodeName: k8s-node1 # 指定pod运行在的node
|
|
|
|
|
containers: # Pod里容器的定义部分
|
|
|
|
|
- name: mysql # 容器的名称
|
|
|
|
|
image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/docker.io/mysql:5.7.44 # 容器对应的docker镜像
|
|
|
|
|
volumeMounts: # 容器内挂载点的定义部分
|
|
|
|
|
- name: time-zone # 容器内挂载点名称
|
|
|
|
|
mountPath: /etc/localtime # 容器内挂载点路径,可以是文件或目录
|
|
|
|
|
- name: mysql-data
|
|
|
|
|
mountPath: /var/lib/mysql # 容器内mysql的数据目录
|
|
|
|
|
- name: mysql-logs
|
|
|
|
|
mountPath: /var/log/mysql # 容器内mysql的日志目录
|
|
|
|
|
ports:
|
|
|
|
|
- containerPort: 3306 # 容器暴露的端口号
|
|
|
|
|
env: # 写入到容器内的环境容量
|
|
|
|
|
- name: MYSQL_ROOT_PASSWORD # 定义了一个mysql的root密码的变量
|
|
|
|
|
value: "root"
|
|
|
|
|
volumes: # 本地需要挂载到容器里的数据卷定义部分
|
|
|
|
|
- name: time-zone # 数据卷名称,需要与容器内挂载点名称一致
|
|
|
|
|
hostPath:
|
|
|
|
|
path: /etc/localtime # 挂载到容器里的路径,将localtime文件挂载到容器里,可让容器使用本地的时区
|
|
|
|
|
- name: mysql-data
|
|
|
|
|
hostPath:
|
|
|
|
|
path: /data/mysql/data # 本地存放mysql数据的目录
|
|
|
|
|
- name: mysql-logs
|
|
|
|
|
hostPath:
|
|
|
|
|
path: /data/mysql/logs # 本地存入mysql日志的目录
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
将 `mysql-deployment.yaml`配置文件上传至虚拟机的 /root 目录下,在 /root 目录下执行命令:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
kubectl create -f mysql.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
执行添加服务的命令(这行不执行应该也不影响结果):
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
kubectl apply -f mysql.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
编写一个提供对外访问的service `mysql-svc.yaml`:
|
|
|
|
|
|
|
|
|
|
```yaml
|
|
|
|
|
apiVersion: v1
|
|
|
|
|
kind: Service
|
|
|
|
|
metadata:
|
|
|
|
|
name: mysql
|
|
|
|
|
labels:
|
|
|
|
|
name: mysql
|
|
|
|
|
spec:
|
|
|
|
|
type: NodePort
|
|
|
|
|
ports:
|
|
|
|
|
- port: 3306
|
|
|
|
|
targetPort: 3306
|
|
|
|
|
nodePort: 30001
|
|
|
|
|
selector:
|
|
|
|
|
app: mysql
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
将 `mysql-svc.yaml`配置文件上传至虚拟机的 /root 目录下,在 /root 目录下执行命令:
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
kubectl create -f mysql-svc.yaml
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
访问数据库并验证其运行正常
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
kubectl get pod
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
删除$pods$
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
kubectl delete pods el-admin-mysql-rc-z2xjr
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
mysqld failed while attempting to check config
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
# 查看日志
|
|
|
|
|
kubectl describe pod mysql-db89ddf68-gf45x
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kubectl get events --field-selector involvedObject.name=mysql-db89ddf68-gf45x
|
|
|
|
|
|
|
|
|
|
kubectl logs mysql-db89ddf68-gf45x -c <container_name>
|
|
|
|
|
|
|
|
|
|
[root@k8s-master ~]# kubectl logs mysql-db89ddf68-gf45x
|
|
|
|
|
2024-09-16 20:45:16+08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.44-1.el7 started.
|
|
|
|
|
2024-09-16 20:45:28+08:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
|
|
|
|
|
command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.lFVXa084HQ
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```shell
|
|
|
|
|
kubectl exec -it mysql-db89ddf68-gf45x --mysql -uroot -pDsideaL147258369
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(密码也是root)
|
|
|
|
|
|
|
|
|
|
## mysql开放远程连接:
|
|
|
|
|
|
|
|
|
|
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
|
|
|
|
|
|
|
|
|
|
flush privileges; #刷新权限表,使配置生效
|
|
|
|
|
|
|
|
|
|
## 开启防火墙端口
|
|
|
|
|
|
|
|
|
|
systemctl start firewalld.service
|
|
|
|
|
|
|
|
|
|
firewall-cmd --zone=public --add-port=6443/tcp --permanent
|
|
|
|
|
|
|
|
|
|
firewall-cmd --zone=public --add-port=30001/tcp --permanent
|
|
|
|
|
|
|
|
|
|
firewall-cmd --reload
|
|
|
|
|
|
|
|
|
|
firewall-cmd --zone=public --list-ports
|
|
|
|
|
|
|
|
|
|
systemctl stop firewalld.service
|
|
|
|
|
|
|
|
|
|
systemctl disable firewalld.service
|
|
|
|
|
|
|
|
|
|
要开放6443端口(k8s集群连接地址)和30001端口(k8s集群mysql端口)
|
|
|
|
|
|
|
|
|
|
## 查看已安装的mysql
|
|
|
|
|
|
|
|
|
|
kubectl get pod
|
|
|
|
|
|
|
|
|
|
kubectl get svc
|
|
|
|
|
|
|
|
|
|
mysql服务安装在default命名空间中,查看其所在节点:
|
|
|
|
|
|
|
|
|
|
kubectl get pod -n default -o wide
|
|
|
|
|
|
|
|
|
|
此次部署的mysql服务被我们指定运行在了 k8s-worker01 节点上。
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
在本地用SQLyog连接到k8s集群的mysql:
|
|
|
|
|
|
|
|
|
|
#### $7.2$ 部署$redis$
|
|
|
|
|
|
|
|
|
|
> https://devpress.csdn.net/k8s/66c9a10413e4054e7e7d4f79.html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### $7.3$ 部署$MongoDB$
|
|
|
|
|
|
|
|
|
|
> https://www.cnblogs.com/gaoyanbing/p/17694272.html
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### $7.4$ 部署$Minio$
|
|
|
|
|
|
|
|
|
|
> https://blog.csdn.net/baidu_35848778/article/details/131436354
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 八、资料
|
|
|
|
|
|
|
|
|
|
**kubeadm部署kubernetes1.29**
|
|
|
|
|
**[kubernetes](https://link.csdn.net/?target=https%3A%2F%2Flink.csdn.net%2F%3Ftarget%3Dhttps%3A%2F%2Fgitcode.com%2Fgh_mirrors%2Fk8s%2Fk8s-deploy%3Futm_source%3Ddevpress_k8s%26login%3Dfrom_csdn) 可能会产生垃圾或者僵尸pod,在删除rc的时候,相应的pod没有被删除,手动删除pod后会自动重新创建,这时一般需要先删除掉相关联的resources**
|
|
|
|
|
|
|
|
|
|
https://blog.csdn.net/ljx1528/article/details/137714292
|
|
|
|
|
**原因**
|
|
|
|
|
|
|
|
|
|
**先删除pod的话,马上会创建一个新的pod,因为[deploy](https://link.csdn.net/?target=https%3A%2F%2Flink.csdn.net%2F%3Ftarget%3Dhttps%3A%2F%2Fgitcode.com%2Fgh_mirrors%2Fk8s%2Fk8s-deploy%3Futm_source%3Ddevpress_k8s%26login%3Dfrom_csdn)ment.yaml文件中定义了副本数量**
|
|
|
|
|
|
|
|
|
|
**正确方法**
|
|
|
|
|
|
|
|
|
|
先删除[deploy](https://link.csdn.net/?target=https%3A%2F%2Flink.csdn.net%2F%3Ftarget%3Dhttps%3A%2F%2Fgitcode.com%2Fgh_mirrors%2Fk8s%2Fk8s-deploy%3Futm_source%3Ddevpress_k8s%26login%3Dfrom_csdn)ment
|
|
|
|
|
查看[deploy](https://link.csdn.net/?target=https%3A%2F%2Flink.csdn.net%2F%3Ftarget%3Dhttps%3A%2F%2Fgitcode.com%2Fgh_mirrors%2Fk8s%2Fk8s-deploy%3Futm_source%3Ddevpress_k8s%26login%3Dfrom_csdn)ment
|
|
|
|
|
|
|
|
|
|
```routeros
|
|
|
|
|
kubectl get deployment
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
删除[deploy](https://link.csdn.net/?target=https%3A%2F%2Flink.csdn.net%2F%3Ftarget%3Dhttps%3A%2F%2Fgitcode.com%2Fgh_mirrors%2Fk8s%2Fk8s-deploy%3Futm_source%3Ddevpress_k8s%26login%3Dfrom_csdn)ment
|
|
|
|
|
|
|
|
|
|
```pgsql
|
|
|
|
|
kubectl delete deployment <name>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
然后再删除pod
|
|
|
|
|
|
|
|
|
|
```pgsql
|
|
|
|
|
kubectl delete pod <name>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
如果pod还在的话
|
|
|
|
|
查看rc和rs
|
|
|
|
|
|
|
|
|
|
```routeros
|
|
|
|
|
kubectl get rc
|
|
|
|
|
kubectl get rs
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
把pod对应的都删除即可
|
|
|
|
|
|
|
|
|
|
```pgsql
|
|
|
|
|
kubectl delete rc <name>
|
|
|
|
|
kubectl delete rs <name>
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|