“K8s应用”的版本间的差异
(→2020) |
|||
第7行: | 第7行: | ||
=2022= | =2022= | ||
[https://cloud.tencent.com/developer/article/2092943 K8S 部署电商项目] | [https://cloud.tencent.com/developer/article/2092943 K8S 部署电商项目] | ||
− | = | + | =2022 laravel= |
<pre> | <pre> | ||
放 mysql数据的 nfs data里面不能有文件 不然会报错 | 放 mysql数据的 nfs data里面不能有文件 不然会报错 |
2023年10月16日 (一) 14:19的版本
目录
Monitoring
进阶
rancher
2022
2022 laravel
放 mysql数据的 nfs data里面不能有文件 不然会报错 log 如下 2023-10-16 13:34:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.43-1.el7 started. 2023-10-16 13:35:04+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql' 2023-10-16 13:35:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.43-1.el7 started. 2023-10-16 13:35:08+00:00 [Note] [Entrypoint]: Initializing database files 2023-10-16T13:35:08.154125Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). 2023-10-16T13:35:08.156183Z 0 [ERROR] --initialize specified but the data directory has files in it. Aborting. 2023-10-16T13:35:08.156235Z 0 [ERROR] Aborting 1. pv apiVersion: v1 kind: PersistentVolume metadata: name: pv01 labels: pvname: pv01 spec: capacity: storage: 10Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle nfs: path: /mydata/k8s server: 192.168.10.103 2. pvc apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-persistentvolumeclaim spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi selector: #matchLabels: #pvname: pv0001 matchExpressions: - {key: pvname, operator: In, values: [pv01]} 3. mysql dp and service kind: Deployment apiVersion: apps/v1 metadata: name: mysql-deployment labels: app: mysql spec: selector: matchLabels: app: mysql strategy: type: Recreate template: metadata: labels: app: mysql spec: containers: - name: mysql image: mysql:5.7 env: - name: MYSQL_ALLOW_EMPTY_PASSWORD value: 'true' ports: - containerPort: 3306 volumeMounts: - mountPath: /var/lib/mysql name: mysql-storage volumes: - name: mysql-storage persistentVolumeClaim: claimName: mysql-persistentvolumeclaim --- kind: Service apiVersion: v1 metadata: name: mysql-service labels: app: mysql spec: selector: app: mysql ports: - port: 3306 targetPort: 3306
每天5分钟的,以前应该有笔记的吧 https://www.cnblogs.com/CloudMan6/p/8323420.html
用 Deployment 运行应用 - 每天5分钟玩转 Docker 容器技术(123)
Kubernetes存储体系 PV PVC
kubernetes中服务的暴露访问方式
2. Loadbalancer 使用NodeIp+Nodeport的方式实现,利用云平台提供的loadbalance服务,像aws、azure、openstack、gce都提供了loadbalance服务
这里不做介绍了
3. Ingress Ingress 使用开源的反向代理负载均衡器来实现对外暴漏服务,比如 Nginx、Apache、Haproxy等。Nginx Ingress 一般有三个组件组成:
Nginx 反向代理负载均衡器 Ingress Controller 可以理解为控制器,它通过不断的跟 Kubernetes API 交互,实时获取后端 Service、Pod 等的变化,比如新增、删除等,然后结合 Ingress 定义的规则生成配置,然后动态更新上边的 Nginx 负载均衡器,并刷新使配置生效,来达到服务自动发现的作用。 Ingress 则是定义规则,通过它定义某个域名的请求过来之后转发到集群中指定的 Service。它可以通过 Yaml 文件定义,可以给一个或多个 Service 定义一个或多个 Ingress 规则。
kubernetes中服务的暴露访问方式kubernetes ingress使用
国内应用例子
k8s 应用部署
mediawiki k8s
k8s wordpress
K8S nginx volume之nfs挂载 没用pv pvc
#首先 nfs 88.122 mkdir /data/k8s/ng && chmod -R 0777/data/k8s/ng cat nfs_nginx.yaml --- apiVersion: apps/v1 kind: Deployment metadata: name: nginx-nfs labels: web: nginx spec: replicas: 2 selector: matchLabels: appname: nginx template: metadata: labels: appname: nginx spec: containers: - name: nginx-nfs image: nginx volumeMounts: - name: nfs-test mountPath: /usr/share/nginx/html/ volumes: - name: nfs-test nfs: server: 192.168.88.122 path: /data/k8s/ng 查看结果 root@k8s-master:~# kubectl exec -it nginx-nfs-8465d697cc-584qd bash root@nginx-nfs-8465d697cc-584qd:/# cd /usr/share/nginx/html/ root@nginx-nfs-8465d697cc-584qd:/usr/share/nginx/html# ls root@nginx-nfs-8465d697cc-584qd:/usr/share/nginx/html# touch 1.html echo '36'>1.html 回来 nfs [root@work2 ~]# cat /data/k8s/ng/1.html 36 问题 coredns 问题 导致 curl IP 没成功
k8s mysql5.7 NFS 持久化
问题 这个有时会断开 不过好像昨天 删除了好多pod pv pvc 后 今天搞了就不会了呢 Aug 31 2021
为什么mysql服务会不可用?为什么严重时整个k8s中的pod都处于pendding状态了呢? 写io是很耗cpu的,更何况这种大量复制。既然服务不可用了,我们使用top命令查看下k8s worker节点机器的各项性能,如下图。发现nfs在同步过程有一个nginx的command的进程cpu竟然达到了99%,us的cpu达到了23.5%,sy的cpu达到了48.6%,很显然,io同步时消耗了大量的cpu,导致mysql服务不可用了,而k8s的pod都会占用宿主机的cpu的资源的,如果宿主机的cpu资源不够pod所申明的cpu,pod将会重新构建,进而进入pod的生命周期中的pendding状态,所有pod都在争抢宿主机cpu的资源。
NFS 搭建
Nfs实现日志集中查看 yum
mkdir -p /data/k8s/mysql #on centos7 yum -y install nfs-utils root@work2 ~]# cat /etc/exports /data/k8s/ 192.168.88.0/24(sync,rw,no_root_squash) systemctl enable nfs systemctl restart nfs
创建命名空间
kubectl create namespace db-mysql
mysql-nfs-pv.yaml
#k8s master cat > /root/mysqltest/mysql-nfs-pv.yaml <<EOF kind: PersistentVolume apiVersion: v1 metadata: name: mysql-nfs-pv namespace: db-mysql spec: accessModes: - ReadWriteOnce capacity: storage: 2Gi persistentVolumeReclaimPolicy: Retain storageClassName: nfs nfs: path: /data/k8s/mysql server: 192.168.88.22 EOF kubectl apply -f mysql-nfs-pv.yaml
mysql-nfs-pvc.yaml
cat > /root/mysqltest/mysql-nfs-pvc.yaml <<EOF kind: PersistentVolumeClaim apiVersion: v1 metadata: name: mysql-nfs-pvc namespace: db-mysql spec: accessModes: - ReadWriteOnce resources: requests: storage: 2Gi storageClassName: nfs EOF kubecte apply -f mysql-nfs-pvc.yaml
mysql-nfs-deploy.yaml
cat > /root/mysqltest/mysql-nfs-deploy.yaml <<EOF apiVersion: apps/v1 kind: Deployment metadata: name: mysql-nfs-deploy namespace: db-mysql spec: replicas: 1 selector: matchLabels: app: mysql_nfs template: metadata: labels: app: mysql_nfs spec: containers: - name: mysql57 image: mysql:5.7 imagePullPolicy: IfNotPresent env: - name: MYSQL_ROOT_PASSWORD value: "123456" args: - --lower_case_table_names=1 ports: - containerPort: 3306 volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql-nfs-pvc EOF kubectl apply -f mysql-nfs-deploy.yam
mysql-nfs-svc.yaml
cat > /root/mysqltest/mysql-nfs-svc.yaml <<EOF apiVersion: v1 kind: Service metadata: name: mysql namespace: db-mysql spec: type: NodePort ports: - port: 3306 targetPort: 3306 nodePort: 32306 selector: app: mysql_nfs EOF
查看相关
kubectl get pods -A -o wide root@k8s-master:~/mysqltest# kubectl get pods -A -o wide | grep mysql-nfs default mysql-nfs-deploy-5f4fc57696-x49mw 1/1 Running 15 (5m27s ago) 84m 10.244.1.2 k8s-node1 <none> <none> root@k8s-master:~/mysqltest#
查看mysql数据 on nfs master
证明 这个nfs没问题呀 # ls /data/k8s/mysql/ auto.cnf ca.pem client-key.pem ib_logfile0 ibtmp1 performance_schema public_key.pem server-key.pem ca-key.pem client-cert.pem ibdata1 ib_logfile1 mysql private_key.pem server-cert.pem [root@work2 ~]#
login mysql and other
kubectl exec -it mysql-nfs-deploy-5f4fc57696-x49mw /bin/bash 直接容器里面 没密码 哈哈 mysql -u root -p ysql> create database evan; 在nfs 服务器 ls /data/k8s/mysql/evan/ db.opt kubectl logs 遇上 mysql有bug kubectl logs mysql-nfs-deploy-5f4fc57696-x49mw We intentionally generate a memory trap 超级教程 k8s部署mysql数据持久化 https://www.cnblogs.com/pluto-charon/p/14411780.html
see also
k8s+mysql+pv+pvc+NFS实现mysql容器编排
VPS
digitalocean
用他的服务 10/mo 如果是自己建呢 有CPU要求呢 还是买他的吧 两台 10/mon 但是自由,试一下这个行不行先, 等于还多了两个vm,不过上次的helm 2还是不成功呢
https://www.digitalocean.com/docs/kubernetes/overview/
vultr
这个看起来贵一点 这个vps下次暂停一下 不要浪费一个月5刀呢
K8s on aliyun
othre
从零开始搭建Kubernetes集群(六、在K8S上部署Redis 集群)
从零开始搭建Kubernetes集群(五、搭建K8S Ingress
从零开始搭建Kubernetes集群(四、搭建K8S Dashboard)
从零开始搭建Kubernetes集群(七、如何监控K8S集群日志)
全面提升,阿里云Docker/Kubernetes(K8S) 日志解决方案与选型对比
从零开始搭建Kubernetes集群(六、在K8S上部署Redis 集群)
Kubernetes(k8s)部署并测试nginx service
个推基于 Docker 和 Kubernetes 的微服务实践
java tomcat
Docker实践 - 安装Docker并在容器里运行tomcat
trouble
使用kube-proxy让外部网络访问K8S service的ClusterIP
telnet master主机的NodePort服务不通的问题