首页
简历
直播
统计
壁纸
留言
友链
关于
Search
1
PVE开启硬件显卡直通功能
2,557 阅读
2
在k8s(kubernetes) 上安装 ingress V1.1.0
2,059 阅读
3
二进制安装Kubernetes(k8s) v1.24.0 IPv4/IPv6双栈
1,922 阅读
4
Ubuntu 通过 Netplan 配置网络教程
1,842 阅读
5
kubernetes (k8s) 二进制高可用安装
1,793 阅读
默认分类
登录
/
注册
Search
chenby
累计撰写
199
篇文章
累计收到
144
条评论
首页
栏目
默认分类
页面
简历
直播
统计
壁纸
留言
友链
关于
搜索到
199
篇与
cby
的结果
2022-06-10
kubernetes 设置 Master 可调度与不可调度
kubernetes 设置 Master 可调度与不可调度语法kubectl taint node [node] key=value[effect][effect] 可取值: [ NoSchedule | PreferNoSchedule | NoExecute ]NoSchedule: 一定不能被调度PreferNoSchedule: 尽量不要调度NoExecute: 不仅不会调度, 还会驱逐Node上已有的Pod取消污点取消污点 [root@k8s-master01 ~]# kubectl taint node k8s-master node-role.kubernetes.io/master-设置污点# 设置为一定不能被调度 [root@k8s-master01 ~]# kubectl taint node k8s-master01 node-role.kubernetes.io/master="":NoSchedule node/k8s-master01 tainted [root@k8s-master01 ~]# kubectl taint node k8s-master02 node-role.kubernetes.io/master="":NoSchedule node/k8s-master02 tainted [root@k8s-master01 ~]# kubectl taint node k8s-master03 node-role.kubernetes.io/master="":NoSchedule node/k8s-master03 tainted [root@k8s-master01 ~]# # 查看污点 [root@k8s-master01 ~]# kubectl describe node | grep Ta Taints: node-role.kubernetes.io/master:NoSchedule Taints: node-role.kubernetes.io/master:NoSchedule Taints: node-role.kubernetes.io/master:NoSchedule Taints: <none> Taints: <none> Taints: <none> Taints: <none> Taints: <none> [root@k8s-master01 ~]# 查看验证# 查看已经调度到maser上的pod没有被驱逐 [root@k8s-master01 ~]# kubectl get pod -o wide NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES default hostname-test-cby-58d85dccdb-7zgjj 1/1 Running 1 (2d1h ago) 19d 172.25.244.195 k8s-master01 <none> <none> default hostname-test-cby-58d85dccdb-8t7zv 1/1 Running 1 (2d1h ago) 19d 172.25.244.196 k8s-master01 <none> <none> default hostname-test-cby-58d85dccdb-9bqsq 1/1 Running 1 (2d1h ago) 19d 172.25.92.74 k8s-master02 <none> <none> default hostname-test-cby-58d85dccdb-jj2ml 1/1 Running 1 (2d1h ago) 19d 172.17.125.3 k8s-node01 <none> <none> default hostname-test-cby-58d85dccdb-k96zl 1/1 Running 1 (2d1h ago) 19d 172.18.195.3 k8s-master03 <none> <none> default hostname-test-cby-58d85dccdb-lng8b 1/1 Running 1 (2d1h ago) 19d 172.29.115.131 k8s-node04 <none> <none> default hostname-test-cby-58d85dccdb-lsrbg 1/1 Running 1 (2d1h ago) 19d 172.25.214.195 k8s-node03 <none> <none> default hostname-test-cby-58d85dccdb-mlv24 1/1 Running 1 (2d1h ago) 19d 172.17.54.131 k8s-node05 <none> <none> default hostname-test-cby-58d85dccdb-p5vc8 1/1 Running 1 (2d1h ago) 19d 172.27.14.195 k8s-node02 <none> <none> default hostname-test-cby-58d85dccdb-z6ptf 1/1 Running 1 (2d1h ago) 19d 172.25.214.196 k8s-node03 <none> <none> [root@k8s-master01 ~]# 设置污点# 设置为不仅不会调度, 还会驱逐Node上已有的Pod [root@k8s-master01 ~]# kubectl taint node k8s-master03 node-role.kubernetes.io/master="":NoExecute node/k8s-master03 tainted [root@k8s-master01 ~]# kubectl taint node k8s-master02 node-role.kubernetes.io/master="":NoExecute node/k8s-master02 tainted [root@k8s-master01 ~]# kubectl taint node k8s-master01 node-role.kubernetes.io/master="":NoExecute node/k8s-master01 tainted # 查看污点 [root@k8s-master01 ~]# kubectl describe node | grep Ta Taints: node-role.kubernetes.io/master:NoExecute Taints: node-role.kubernetes.io/master:NoExecute Taints: node-role.kubernetes.io/master:NoExecute Taints: <none> Taints: <none> Taints: <none> Taints: <none> Taints: <none> [root@k8s-master01 ~]# 查看验证# 查看已经调度到master节点的pod已进行驱逐 [root@k8s-master01 ~]# kubectl get pod -A -o wide NAMESPACE NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES default mysql-0 2/2 Running 0 34m 172.27.14.206 k8s-node02 <none> <none> default mysql-1 2/2 Running 0 34m 172.17.125.11 k8s-node01 <none> <none> default mysql-2 2/2 Terminating 0 34m 172.18.195.10 k8s-master03 <none> <none> [root@k8s-master01 ~]# https://www.oiox.cn/https://www.chenby.cn/https://cby-chen.github.io/https://blog.csdn.net/qq_33921750https://my.oschina.net/u/3981543https://www.zhihu.com/people/chen-bu-yun-2https://segmentfault.com/u/hppyvyv6/articleshttps://juejin.cn/user/3315782802482007https://cloud.tencent.com/developer/column/93230https://www.jianshu.com/u/0f894314ae2chttps://www.toutiao.com/c/user/token/MS4wLjABAAAAeqOrhjsoRZSj7iBJbjLJyMwYT5D0mLOgCoo4pEmpr4A/CSDN、GitHub、知乎、开源中国、思否、掘金、简书、腾讯云、今日头条、个人博客、全网可搜《小陈运维》文章主要发布于微信公众号:《Linux运维交流社区》
2022年06月10日
526 阅读
0 评论
1 点赞
2022-06-09
kubernetes 启用 PHP + Nginx 网页环境
kubernetes 启用 PHP + Nginx 网页环境传统安装方式进行安装步骤较多,使用kubernetes可以实现快速启用环境,在测试或者线上都可以做到快速 启用编写 yaml 文件[root@k8s-master01 ~]# vim PHP-Nginx-Deployment-ConfMap-Service.yaml [root@k8s-master01 ~]# cat PHP-Nginx-Deployment-ConfMap-Service.yaml kind: Service # 对象类型 apiVersion: v1 # api 版本 metadata: # 元数据 name: php-fpm-nginx #Service 服务名 spec: type: NodePort # 类型为nodeport selector: #标签选择器 app: php-fpm-nginx ports: #端口信息 - port: 80 # 容器端口80 protocol: TCP #tcp类型 targetPort: 80 # Service 将 nginx 容器的 80 端口暴露出来 --- kind: ConfigMap # 对象类型 apiVersion: v1 # api 版本 metadata: # 元数据 name: nginx-config # 对象名称 data: # key-value 数据集合 nginx.conf: | # 将 nginx config 配置写入 ConfigMap 中,经典的 php-fpm 代理设置,这里就不再多说了 user nginx; worker_processes auto; error_log /var/log/nginx/error.log notice; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; keepalive_timeout 65; server { listen 80 default_server; listen [::]:80 default_server; root /var/www/html; index index.php; server_name _; if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f $request_filename/index.php) { rewrite (.*) $1/index.php; } if (!-f $request_filename) { rewrite (.*) /index.php; } location / { try_files $uri $uri/ =404; } location ~ \.php$ { include fastcgi_params; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } } include /etc/nginx/conf.d/*.conf; } --- kind: Deployment # 对象类型 apiVersion: apps/v1 # api 版本 metadata: # 元数据 name: php-fpm-nginx # Deployment 对象名称 spec: # Deployment 对象规约 selector: # 选择器 matchLabels: # 标签匹配 app: php-fpm-nginx replicas: 3 # 副本数量 template: # 模版 metadata: # Pod 对象的元数据 labels: # Pod 对象的标签 app: php-fpm-nginx spec: # Pod 对象规约 containers: # 这里设置了两个容器 - name: php-fpm # 第一个容器名称 image: php:7.4.29-fpm # 容器镜像 imagePullPolicy: IfNotPresent #镜像拉取策略 livenessProbe: # 存活探测 initialDelaySeconds: 5 # 容器启动后要等待多少秒后才启动存活和就绪探测器 periodSeconds: 10 # 每多少秒执行一次存活探测 tcpSocket: # 监测tcp端口 port: 9000 #监测端口 readinessProbe: # 就绪探测 initialDelaySeconds: 5 # 容器启动后要等待多少秒后才启动存活和就绪探测器 periodSeconds: 10 # 每多少秒执行一次存活探测 tcpSocket: # 监测tcp端口 port: 9000 #监测端口 resources: # 资源约束 requests: # 最小限制 memory: "64Mi" # 内存最新64M cpu: "250m" # CPU最大使用0.25核 limits: # 最大限制 memory: "128Mi" # 内存最新128M cpu: "500m" # CPU最大使用0.5核 ports: - containerPort: 9000 # php-fpm 端口 volumeMounts: # 挂载数据卷 - mountPath: /var/www/html # 挂载两个容器共享的 volume name: nginx-www lifecycle: # 生命周期 postStart: # 当容器处于 postStart 阶段时,执行一下命令 exec: command: ["/bin/sh", "-c", "echo startup..."] # 将 /app/index.php 复制到挂载的 volume preStop: exec: command: - sh - '-c' - sleep 5 && kill -SIGQUIT 1 # 优雅退出 - name: nginx # 第二个容器名称 image: nginx # 容器镜像 imagePullPolicy: IfNotPresent livenessProbe: # 存活探测 initialDelaySeconds: 5 # 容器启动后要等待多少秒后才启动存活和就绪探测器 periodSeconds: 10 # 每多少秒执行一次存活探测 httpGet: # 以httpGet方式进行探测 path: / # 探测路径 port: 80 # 探测端口 readinessProbe: # 就绪探测 initialDelaySeconds: 5 # 容器启动后要等待多少秒后才启动存活和就绪探测器 periodSeconds: 10 # 每多少秒执行一次存活探测 httpGet: # 以httpGet方式进行探测 path: / # 探测路径 port: 80 # 探测端口 resources: # 资源约束 requests: # 最小限制 memory: "64Mi" # 内存最新64M cpu: "250m" # CPU最大使用0.25核 limits: # 最大限制 memory: "128Mi" # 内存最新128M cpu: "500m" # CPU最大使用0.5核 ports: - containerPort: 80 # nginx 端口 volumeMounts: # nginx 容器挂载了两个 volume,一个是与 php-fpm 容器共享的 volume,另外一个是配置了 nginx.conf 的 volume - mountPath: /var/www/html # 挂载两个容器共享的 volume name: nginx-www - mountPath: /etc/nginx/nginx.conf # 挂载配置了 nginx.conf 的 volume subPath: nginx.conf name: nginx-config lifecycle: preStop: exec: command: - sh - '-c' - sleep 5 && /usr/sbin/nginx -s quit # 优雅退出 volumes: - name: nginx-www # 网站文件通过nfs挂载 nfs: path: /html/ server: 192.168.1.123 - name: nginx-config configMap: # configMap name: nginx-config部署网站 # 下载网站代码 wget https://typecho.org/downloads/1.1-17.10.30-release.tar.gz # 解压源码包 tar xvf 1.1-17.10.30-release.tar.gz #移动到当前目录下 mv build/* . #设置权限 chmod 777 -R *创建资源kubectl apply -f PHP-Nginx-Deployment-ConfMap-Service.yaml测试环境kubectl get pod -l app=php-fpm-nginx NAME READY STATUS RESTARTS AGE php-fpm-nginx-8b4bfb457-24bpd 2/2 Running 1 (6m34s ago) 16m php-fpm-nginx-8b4bfb457-fvqd6 2/2 Running 2 (5m39s ago) 16m php-fpm-nginx-8b4bfb457-kmzsc 2/2 Running 1 (6m34s ago) 16m kubectl get configmaps | grep nginx NAME DATA AGE nginx-config 1 17m kubectl get svc | grep nginx php-fpm-nginx NodePort 10.98.66.104 <none> 80:31937/TCP 16mhttps://www.oiox.cn/https://www.chenby.cn/https://cby-chen.github.io/https://blog.csdn.net/qq_33921750https://my.oschina.net/u/3981543https://www.zhihu.com/people/chen-bu-yun-2https://segmentfault.com/u/hppyvyv6/articleshttps://juejin.cn/user/3315782802482007https://cloud.tencent.com/developer/column/93230https://www.jianshu.com/u/0f894314ae2chttps://www.toutiao.com/c/user/token/MS4wLjABAAAAeqOrhjsoRZSj7iBJbjLJyMwYT5D0mLOgCoo4pEmpr4A/CSDN、GitHub、知乎、开源中国、思否、掘金、简书、腾讯云、今日头条、个人博客、全网可搜《小陈运维》文章主要发布于微信公众号:《Linux运维交流社区》
2022年06月09日
291 阅读
0 评论
0 点赞
2022-06-08
Kubernetes 部署 MySQL 高可用读写分离
Kubernetes 部署 MySQL 集群简介: 在有状态应用中,MySQL是我们最常见也是最常用的。本文我们将实战部署一个一组多从的MySQL集群。一、配置准备configMapcat > mysql-configmap.yaml << EOF apiVersion: v1 kind: ConfigMap metadata: name: mysql labels: app: mysql data: master.cnf: | # Apply this config only on the master. [mysqld] log-bin slave.cnf: | # Apply this config only on slaves. [mysqld] super-read-only EOFconfigMap可以将配置文件和镜像解耦开。上面的配置意思是,创建一个master.cnf文件配置内容为:log-bin,即开启bin-log日志,供主节点使用。创建一个slave.cnf文件配置内容为:super-read-only,设为该节点只读,供备用节点使用。servicecat > mysql-services.yaml << EOF apiVersion: v1 kind: Service metadata: name: mysql labels: app: mysql spec: ports: - name: mysql port: 3306 clusterIP: None selector: app: mysql --- # Client service for connecting to any MySQL instance for reads. # For writes, you must instead connect to the master: mysql-0.mysql. apiVersion: v1 kind: Service metadata: name: mysql-read labels: app: mysql spec: ports: - name: mysql port: 3306 selector: app: mysql EOFStatefulSetapiVersion: apps/v1 kind: StatefulSet metadata: name: mysql spec: selector: matchLabels: app: mysql serviceName: mysql replicas: 3 template: metadata: labels: app: mysql spec: # 设置初始化容器,进行一些准备工作 initContainers: - name: init-mysql image: mysql:5.7 # 为每个MySQL节点配置service-id # 如果节点序号是0,则使用master的配置, 其余节点使用slave的配置 command: - bash - "-c" - | set -ex # 基于 Pod 序号生成 MySQL 服务器的 ID。 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1 ordinal=${BASH_REMATCH[1]} echo [mysqld] > /mnt/conf.d/server-id.cnf # 添加偏移量以避免使用 server-id=0 这一保留值。 echo server-id=$((100 + $ordinal)) >> /mnt/conf.d/server-id.cnf # Copy appropriate conf.d files from config-map to emptyDir. # 将合适的 conf.d 文件从 config-map 复制到 emptyDir。 if [[ $ordinal -eq 0 ]]; then cp /mnt/config-map/master.cnf /mnt/conf.d/ else cp /mnt/config-map/slave.cnf /mnt/conf.d/ fi volumeMounts: - name: conf mountPath: /mnt/conf.d - name: config-map mountPath: /mnt/config-map - name: clone-mysql image: registry.cn-hangzhou.aliyuncs.com/chenby/xtrabackup:1.0 # 为除了节点序号为0的主节点外的其它节点,备份前一个节点的数据 command: - bash - "-c" - | set -ex # 如果已有数据,则跳过克隆。 [[ -d /var/lib/mysql/mysql ]] && exit 0 # 跳过主实例(序号索引 0)的克隆。 [[ `hostname` =~ -([0-9]+)$ ]] || exit 1 ordinal=${BASH_REMATCH[1]} [[ $ordinal -eq 0 ]] && exit 0 # 从原来的对等节点克隆数据。 ncat --recv-only mysql-$(($ordinal-1)).mysql 3307 | xbstream -x -C /var/lib/mysql # 准备备份。 xtrabackup --prepare --target-dir=/var/lib/mysql volumeMounts: - name: data mountPath: /var/lib/mysql subPath: mysql - name: conf mountPath: /etc/mysql/conf.d containers: - name: mysql image: mysql:5.7 # 设置支持免密登录 env: - name: MYSQL_ALLOW_EMPTY_PASSWORD value: "1" ports: - name: mysql containerPort: 3306 volumeMounts: - name: data mountPath: /var/lib/mysql subPath: mysql - name: conf mountPath: /etc/mysql/conf.d resources: # 设置启动pod需要的资源,官方文档上需要500m cpu,1Gi memory。 # 我本地测试的时候,会因为资源不足,报1 Insufficient cpu, 1 Insufficient memory错误,所以我改小了点 requests: # m是千分之一的意思,100m表示需要0.1个cpu cpu: 1024m # Mi是兆的意思,需要100M 内存 memory: 1Gi livenessProbe: # 使用mysqladmin ping命令,对MySQL节点进行探活检测 # 在节点部署完30秒后开始,每10秒检测一次,超时时间为5秒 exec: command: ["mysqladmin", "ping"] initialDelaySeconds: 30 periodSeconds: 10 timeoutSeconds: 5 readinessProbe: # 对节点服务可用性进行检测, 启动5秒后开始,每2秒检测一次,超时时间1秒 exec: # 检查我们是否可以通过 TCP 执行查询(skip-networking 是关闭的)。 command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"] initialDelaySeconds: 5 periodSeconds: 2 timeoutSeconds: 1 - name: xtrabackup image: registry.cn-hangzhou.aliyuncs.com/chenby/xtrabackup:1.0 ports: - name: xtrabackup containerPort: 3307 # 开始进行备份文件校验、解析和开始同步 command: - bash - "-c" - | set -ex cd /var/lib/mysql # 确定克隆数据的 binlog 位置(如果有的话)。 if [[ -f xtrabackup_slave_info && "x$(<xtrabackup_slave_info)" != "x" ]]; then # XtraBackup 已经生成了部分的 “CHANGE MASTER TO” 查询 # 因为我们从一个现有副本进行克隆。(需要删除末尾的分号!) cat xtrabackup_slave_info | sed -E 's/;$//g' > change_master_to.sql.in # 在这里要忽略 xtrabackup_binlog_info (它是没用的)。 rm -f xtrabackup_slave_info xtrabackup_binlog_info elif [[ -f xtrabackup_binlog_info ]]; then # 我们直接从主实例进行克隆。解析 binlog 位置。 [[ `cat xtrabackup_binlog_info` =~ ^(.*?)[[:space:]]+(.*?)$ ]] || exit 1 rm -f xtrabackup_binlog_info xtrabackup_slave_info echo "CHANGE MASTER TO MASTER_LOG_FILE='${BASH_REMATCH[1]}',\ MASTER_LOG_POS=${BASH_REMATCH[2]}" > change_master_to.sql.in fi # 检查我们是否需要通过启动复制来完成克隆。 if [[ -f change_master_to.sql.in ]]; then echo "Waiting for mysqld to be ready (accepting connections)" until mysql -h 127.0.0.1 -e "SELECT 1"; do sleep 1; done echo "Initializing replication from clone position" mysql -h 127.0.0.1 \ -e "$(<change_master_to.sql.in), \ MASTER_HOST='mysql-0.mysql', \ MASTER_USER='root', \ MASTER_PASSWORD='', \ MASTER_CONNECT_RETRY=10; \ START SLAVE;" || exit 1 # 如果容器重新启动,最多尝试一次。 mv change_master_to.sql.in change_master_to.sql.orig fi # 当对等点请求时,启动服务器发送备份。 exec ncat --listen --keep-open --send-only --max-conns=1 3307 -c \ "xtrabackup --backup --slave-info --stream=xbstream --host=127.0.0.1 --user=root" volumeMounts: - name: data mountPath: /var/lib/mysql subPath: mysql - name: conf mountPath: /etc/mysql/conf.d resources: requests: cpu: 100m memory: 100Mi volumes: - name: conf emptyDir: {} - name: config-map configMap: name: mysql # 设置PVC volumeClaimTemplates: - metadata: name: data annotations: # 配置PVC使用nfs动态供给 volume.beta.kubernetes.io/storage-class: nfs-storage spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 1Gi二、创建所需资源# 创建configMap kubectl apply -f mysql-configmap.yaml # 创建service kubectl apply -f mysql-services.yaml # 创建statefulSet kubectl apply -f mysql-statefulset.yaml # 查看创建过程 kubectl get pods --watch mysql-0 0/2 Pending 0 0s mysql-0 0/2 Pending 0 0s mysql-0 0/2 Init:0/2 0 0s mysql-0 0/2 Init:0/2 0 1s mysql-0 0/2 Init:1/2 0 2s mysql-0 0/2 PodInitializing 0 3s mysql-0 1/2 Running 0 4s mysql-0 2/2 Running 0 8s mysql-1 0/2 Pending 0 0s mysql-1 0/2 Pending 0 0s mysql-1 0/2 Init:0/2 0 0s mysql-1 0/2 Init:0/2 0 1s mysql-1 0/2 Init:1/2 0 1s mysql-1 0/2 PodInitializing 0 2s mysql-1 1/2 Running 0 3s mysql-1 2/2 Running 0 8s mysql-2 0/2 Pending 0 0s mysql-2 0/2 Pending 0 0s mysql-2 0/2 Init:0/2 0 0s mysql-2 0/2 Init:0/2 0 1s mysql-2 0/2 Init:1/2 0 2s mysql-2 0/2 PodInitializing 0 3s mysql-2 1/2 Running 0 4s mysql-2 2/2 Running 0 9s三、测试主库进入pod进行操作# 进入到pod mysql-0中,进行测试 kubectl exec -it mysql-0 bash # 用mysql-client链接mysql-0 mysql -h mysql-0 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 276 Server version: 5.7.38-log MySQL Community Server (GPL) Copyright (c) 2000, 2022, 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>创建库、表# 创建数据库test mysql> create database cby; Query OK, 1 row affected (0.00 sec) # 使用test库 mysql> use cby; Database changed # 创建message表 mysql> create table message (message varchar(50)); Query OK, 0 rows affected (0.01 sec) # 查看message表结构 mysql> show create table message; +---------+------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------+------------------------------------------------------------------------------------------------------+ | message | CREATE TABLE `message` ( `message` varchar(50) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +---------+------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) 插入数据# 插入 mysql> insert into message value("hello chenby"); Query OK, 1 row affected (0.00 sec) # 查看 mysql> select * from message; +---------------+ | message | +---------------+ | hello chenby | +---------------+ 1 row in set (0.00 sec) 四、测试备库连接mysql-1 mysql -h mysql-1.mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 362 Server version: 5.7.38 MySQL Community Server (GPL) Copyright (c) 2000, 2022, 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> mysql> 查看库、表结构# 查看数据库列表 mysql> show databases; +------------------------+ | Database | +------------------------+ | information_schema | | cby | | mysql | | performance_schema | | sys | | test | | xtrabackup_backupfiles | +------------------------+ 7 rows in set (0.01 sec) # 使用cby库 mysql> use cby; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> # 查看表列表 mysql> show tables; +---------------+ | Tables_in_cby | +---------------+ | message | +---------------+ 1 row in set (0.00 sec) # 查看message表结构 mysql> show create table message; +---------+------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------+------------------------------------------------------------------------------------------------------+ | message | CREATE TABLE `message` ( `message` varchar(50) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 | +---------+------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> # 查询数据 mysql> select * from message; +---------------+ | message | +---------------+ | hello chenby | +---------------+ 1 row in set (0.00 sec) mysql> # 写入数据 mysql> insert into message values("hello world"); ERROR 1290 (HY000): The MySQL server is running with the --super-read-only option so it cannot execute this statement mysql> # 这是因为mysql-1是一个只读备库,无法进行写操作。五、测试mysql-read服务循环中运行 SELECT @@server_idkubectl run mysql-client-loop --image=mysql:5.7 -i -t --rm --restart=Never --\ > bash -ic "while sleep 1; do mysql -h mysql-read -e 'SELECT @@server_id,NOW()'; done" If you don't see a command prompt, try pressing enter. +-------------+---------------------+ | @@server_id | NOW() | +-------------+---------------------+ | 102 | 2022-06-07 09:52:19 | +-------------+---------------------+ +-------------+---------------------+ | @@server_id | NOW() | +-------------+---------------------+ | 101 | 2022-06-07 09:52:20 | +-------------+---------------------+ +-------------+---------------------+ | @@server_id | NOW() | +-------------+---------------------+ | 100 | 2022-06-07 09:52:21 | +-------------+---------------------+ 六、扩缩容# 扩容至5副本 kubectl scale statefulset mysql --replicas=5 # 查看扩容过程 kubectl get pods --watch mysql-3 0/2 Pending 0 0s mysql-3 0/2 Pending 0 1s mysql-3 0/2 Pending 0 2s mysql-3 0/2 Init:0/2 0 2s mysql-3 0/2 Init:0/2 0 2s mysql-3 0/2 Init:0/2 0 3s mysql-3 0/2 Init:1/2 0 4s mysql-3 0/2 Init:1/2 0 5s mysql-3 0/2 PodInitializing 0 12s mysql-3 1/2 Error 0 13s mysql-3 1/2 Running 1 (2s ago) 14s mysql-3 2/2 Running 1 (6s ago) 18s mysql-4 0/2 Pending 0 0s mysql-4 0/2 Pending 0 0s mysql-4 0/2 Pending 0 2s mysql-4 0/2 Init:0/2 0 2s mysql-4 0/2 Init:0/2 0 2s mysql-4 0/2 Init:1/2 0 3s mysql-4 0/2 Init:1/2 0 4s mysql-4 0/2 PodInitializing 0 12s mysql-4 1/2 Error 0 13s mysql-4 1/2 Running 1 (1s ago) 14s mysql-4 2/2 Running 1 (7s ago) 20s # 缩容只2副本 kubectl scale statefulset mysql --replicas=2 # 查看缩容过程 kubectl get pods --watch mysql-4 2/2 Terminating 1 (74s ago) 87s mysql-4 2/2 Terminating 1 (104s ago) 117s mysql-4 0/2 Terminating 1 118s mysql-4 0/2 Terminating 1 118s mysql-4 0/2 Terminating 1 118s mysql-3 2/2 Terminating 1 (2m4s ago) 2m16s mysql-3 2/2 Terminating 1 (2m34s ago) 2m46s mysql-3 0/2 Terminating 1 2m47s mysql-3 0/2 Terminating 1 2m47s mysql-3 0/2 Terminating 1 2m47s mysql-2 2/2 Terminating 0 16m mysql-2 2/2 Terminating 0 16m mysql-2 0/2 Terminating 0 16m mysql-2 0/2 Terminating 0 16m mysql-2 0/2 Terminating 0 16mhttps://www.oiox.cn/ https://www.chenby.cn/ https://cby-chen.github.io/ https://blog.csdn.net/qq_33921750 https://my.oschina.net/u/3981543 https://www.zhihu.com/people/chen-bu-yun-2 https://segmentfault.com/u/hppyvyv6/articles https://juejin.cn/user/3315782802482007 https://cloud.tencent.com/developer/column/93230 https://www.jianshu.com/u/0f894314ae2c https://www.toutiao.com/c/user/token/MS4wLjABAAAAeqOrhjsoRZSj7iBJbjLJyMwYT5D0mLOgCoo4pEmpr4A/CSDN、GitHub、知乎、开源中国、思否、掘金、简书、腾讯云、今日头条、个人博客、全网可搜《小陈运维》文章主要发布于微信公众号:《Linux运维交流社区》
2022年06月08日
481 阅读
1 评论
0 点赞
2022-06-03
安装 Metrics server
安装 Metrics serverMetrics Server 是 Kubernetes 内置自动缩放管道的可扩展、高效的容器资源指标来源。Metrics Server 从 Kubelets 收集资源指标,并通过Metrics API在 Kubernetes apiserver 中公开它们,以供 Horizontal Pod Autoscaler和Vertical Pod Autoscaler使用。Metrics API 也可以通过 访问kubectl top,从而更容易调试自动缩放管道。单机版单机版 wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml 查看镜像地址 grep -rn image components.yaml 140: image: k8s.gcr.io/metrics-server/metrics-server:v0.6.1 141: imagePullPolicy: IfNotPresent 设置镜像地址为阿里云 sed -i "s#k8s.gcr.io/metrics-server#registry.cn-hangzhou.aliyuncs.com/chenby#g" components.yaml 查看镜像地址已更新 grep -rn image components.yaml 140: image: registry.cn-hangzhou.aliyuncs.com/chenby/metrics-server:v0.6.1 141: imagePullPolicy: IfNotPresent args添加tls证书配置选项 vim components.yaml 添加"- --kubelet-insecure-tls" 例: args: - --cert-dir=/tmp - --secure-port=4443 - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname - --kubelet-use-node-status-port - --metric-resolution=15s - --kubelet-insecure-tls image: registry.cn-hangzhou.aliyuncs.com/chenby/metrics-server:v0.6.1 执行配置 kubectl apply -f components.yaml serviceaccount/metrics-server created clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created clusterrole.rbac.authorization.k8s.io/system:metrics-server created rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created service/metrics-server created deployment.apps/metrics-server created apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created 高可用版本高可用版本 wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/high-availability.yaml 查看镜像地址 grep -rn image high-availability.yaml 150: image: k8s.gcr.io/metrics-server/metrics-server:v0.6.1 151: imagePullPolicy: IfNotPresent 设置镜像地址为阿里云 sed -i "s#k8s.gcr.io/metrics-server#registry.cn-hangzhou.aliyuncs.com/chenby#g" high-availability.yaml 查看镜像地址已更新 grep -rn image high-availability.yaml 150: image: registry.cn-hangzhou.aliyuncs.com/chenby/metrics-server:v0.6.1 151: imagePullPolicy: IfNotPresent args添加tls证书配置选项 vim high-availability.yaml 添加"- --kubelet-insecure-tls" 例: args: - --cert-dir=/tmp - --secure-port=4443 - --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname - --kubelet-use-node-status-port - --metric-resolution=15s - --kubelet-insecure-tls image: registry.cn-hangzhou.aliyuncs.com/chenby/metrics-server:v0.6.1 执行配置 kubectl apply -f high-availability.yaml serviceaccount/metrics-server created clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created clusterrole.rbac.authorization.k8s.io/system:metrics-server created rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created service/metrics-server created deployment.apps/metrics-server created Warning: policy/v1beta1 PodDisruptionBudget is deprecated in v1.21+, unavailable in v1.25+; use policy/v1 PodDisruptionBudget poddisruptionbudget.policy/metrics-server created apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created验证查看metrics资源 kubectl get pod -n kube-system | grep metrics metrics-server-65fb95948b-2bcht 1/1 Running 0 32s metrics-server-65fb95948b-vqp5s 1/1 Running 0 32s 查看node资源情况 kubectl top node NAME CPU(cores) CPU% MEMORY(bytes) MEMORY% k8s-master01 127m 1% 2439Mi 64% k8s-node01 50m 0% 1825Mi 23% k8s-node02 53m 0% 1264Mi 16% 查看pod资源情况 kubectl top pod NAME CPU(cores) MEMORY(bytes) chenby-57479d5997-44926 0m 10Mi chenby-57479d5997-tbpqc 0m 11Mi chenby-57479d5997-w8cp2 0m 6Mi https://www.oiox.cn/https:/blog.oiox.cn/https://www.chenby.cn/https://cby-chen.github.io/https://blog.csdn.net/qq_33921750https://my.oschina.net/u/3981543https://www.zhihu.com/people/chen-bu-yun-2https://segmentfault.com/u/hppyvyv6/articleshttps://juejin.cn/user/3315782802482007https://cloud.tencent.com/developer/column/93230https://www.jianshu.com/u/0f894314ae2chttps://www.toutiao.com/c/user/token/MS4wLjABAAAAeqOrhjsoRZSj7iBJbjLJyMwYT5D0mLOgCoo4pEmpr4A/CSDN、GitHub、知乎、开源中国、思否、掘金、简书、腾讯云、今日头条、个人博客、全网可搜《小陈运维》文章主要发布于微信公众号:《Linux运维交流社区》
2022年06月03日
509 阅读
0 评论
0 点赞
2022-05-29
二进制安装 Kubernetes(k8s)
二进制安装 Kubernetes(k8s)Kubernetes 开源不易,帮忙点个star,谢谢了介绍kubernetes(k8s) 二进制安装后续尽可能第一时间更新新版本文档1.23.3 和 1.23.4 和 1.23.5 和 1.23.6 和 1.24.0 和 1.24.1 文档以及安装包已生成。若不使用IPv6,不对主机进行配置IPv6地址即可,不影响后续,但是集群依旧是IPv6的。(下载更快)我的网盘共享:https://pan.oiox.cn/s/PetV手动项目地址:https://github.com/cby-chen/Kubernetes脚本项目地址:https://github.com/cby-chen/Binary_installation_of_Kuberneteskubernetes 1.24 变化较大,详细见:https://kubernetes.io/zh/blog/2022/04/07/upcoming-changes-in-kubernetes-1-24/文档每个版本文档如下链接https://github.com/cby-chen/Kubernetes/blob/main/v1.23.3-binary-install.mdhttps://github.com/cby-chen/Kubernetes/blob/main/v1.23.4-binary-install.mdhttps://github.com/cby-chen/Kubernetes/blob/main/v1.23.5-binary-install.mdhttps://github.com/cby-chen/Kubernetes/blob/main/v1.23.6-binary-install.mdhttps://github.com/cby-chen/Kubernetes/blob/main/v1.24.0-binary-install-IPv6-IPv4.mdhttps://github.com/cby-chen/Kubernetes/blob/main/v1.24.1-binary-install-IPv6-IPv4.mdhttps://github.com/cby-chen/Kubernetes/blob/main/v1.24.0-binary-install-IPv6-IPv4-Three-Masters-Two-Slaves.md安装包(下载更快)我自己的网盘:https://pan.oiox.cn/s/PetV每个初始版本会打上releases,安装包在releases页面https://github.com/cby-chen/Kubernetes/releases注意:1.23.3 版本当时没想到会后续更新,所以当时命名不太规范。wget https://github.com/cby-chen/Kubernetes/releases/download/cby/Kubernetes.tarwget https://github.com/cby-chen/Kubernetes/releases/download/v1.23.4/kubernetes-v1.23.4.tarwget https://github.com/cby-chen/Kubernetes/releases/download/v1.23.5/kubernetes-v1.24.5.tarwget https://github.com/cby-chen/Kubernetes/releases/download/v1.23.6/kubernetes-v1.23.6.tarwget https://github.com/cby-chen/Kubernetes/releases/download/v1.24.0/kubernetes-v1.24.0.tarwget https://github.com/cby-chen/Kubernetes/releases/download/v1.24.1/kubernetes-v1.24.1.tar其他建议在 Kubernetes 查看文档,后续会陆续更新文档小陈网站:https://blog.oiox.cn/https://www.oiox.cn/https://www.chenby.cn/https://cby-chen.github.io/关于小陈:https://www.oiox.cn/index.php/start-page.html其他文档请查看如下,欢迎关注微信公众号《Linux运维交流社区》:https://www.oiox.cn/ https://www.chenby.cn/ https://cby-chen.github.io/ https://blog.csdn.net/qq_33921750 https://my.oschina.net/u/3981543 https://www.zhihu.com/people/chen-bu-yun-2 https://segmentfault.com/u/hppyvyv6/articles https://juejin.cn/user/3315782802482007 https://cloud.tencent.com/developer/column/93230 https://www.jianshu.com/u/0f894314ae2c https://www.toutiao.com/c/user/token/MS4wLjABAAAAeqOrhjsoRZSj7iBJbjLJyMwYT5D0mLOgCoo4pEmpr4A/CSDN、GitHub、知乎、开源中国、思否、掘金、简书、腾讯云、今日头条、个人博客、全网可搜《小陈运维》文章主要发布于微信公众号:《Linux运维交流社区》
2022年05月29日
332 阅读
0 评论
0 点赞
1
...
16
17
18
...
40