目录
压测
[root@master-1 ai]# cat wordpress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql01
template:
metadata:
labels:
app: mysql01
spec:
containers:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "123"
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_USER
value: wp-
- name: MYSQL_PASSWORD
value: "123"
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
hostPath:
path: /data/db
---
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
selector:
app: mysql01
ports:
- protocol: TCP
port: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: http
env:
- name: WORDPRESS_DB_HOST
value: mysql
- name: WORDPRESS_DB_USER
value: wp-
- name: WORDPRESS_DB_PASSWORD
value: "123"
- name: WORDPRESS_DB_NAME
value: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
resources:
requests:
cpu: 200m
volumes:
- name: wordpress-persistent-storage
hostPath:
path: /data/wordpress
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
spec:
type: NodePort
selector:
app: wordpress
ports:
- name: http
protocol: TCP
port: 80
targetPort: http
## hpa
[root@master-1 ai]# cat hpa-wordpress.yaml
apiVersion: "autoscaling/v1"
kind: "HorizontalPodAutoscaler"
metadata:
name: php-apache
namespace: default
spec:
maxReplicas: 10
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: wordpress
targetCPUUtilizationPercentage: 50
## 压测工具siege
[root@master-1 ai]# yum install -y siege
# 50个并发,持续1分钟
[root@master-1 ai]# siege -c 50 -t 1m http://10.0.0.111:31963/wp-admin/install.php
# 查看每个服务的cpu占用(解决的疑问点:新启动的服务是不是缓解服务压力了)
[root@master-1 ai]# kubectl top pod
NAME CPU(cores) MEMORY(bytes)
mysql-5bf4b6549b-lc87m 77m 223Mi
wordpress-8549676bc6-26lxj 29m 99Mi
wordpress-8549676bc6-gkwvr 30m 110Mi
wordpress-8549676bc6-nzwwk 24m 95Mi
wordpress-8549676bc6-pp9w6 45m 125Mi
wordpress-8549676bc6-swgx8 28m 107Mi
wordpress-8549676bc6-xwtzl 29m 118Mi
wordpress-8549676bc6-zt67p 36m 115Mi
[root@master-1 cf]# cat ../wordpress.yaml
apiVersion: v1
kind: Service
metadata:
name: wp-pod
spec:
type: NodePort
selector:
name: wp-dp
ports:
- name: http
protocol: TCP
port: 80
targetPort: http
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wp-dp01
spec:
replicas: 1
selector:
matchLabels:
name: wp-dp
template:
metadata:
name: wp
labels:
name: wp-dp
spec:
volumes:
- name: guazaidian
hostPath:
path: /data/db
- name: guazaidian2
hostPath:
path: /data/wordpress
containers:
- name: wordpress
image: wordpress:latest
imagePullPolicy: IfNotPresent
env:
- name: WORDPRESS_DB_HOST
value: "127.0.0.1"
- name: WORDPRESS_DB_USER
value: wp-
- name: WORDPRESS_DB_PASSWORD
value: "123"
- name: WORDPRESS_DB_NAME
value: wordpress
ports:
- containerPort: 80
name: http
volumeMounts:
- name: guazaidian2
mountPath: /var/www/html
resources:
requests:
cpu: "200m"
- name: db
image: mysql:5.7
imagePullPolicy: IfNotPresent
env:
- name: MYSQL_ROOT_PASSWORD
value: "123"
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_USER
value: wp-
- name: MYSQL_PASSWORD
value: "123"
ports:
- containerPort: 3306
volumeMounts:
- name: guazaidian
mountPath: /var/lib/mysql
[root@master-1 ai]# cat wordpress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql // 指定pod的标签
template:
metadata:
labels: // 打pod的标签()
app: mysql // pod的标签
spec:
containers:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "123"
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_USER
value: wp-
- name: MYSQL_PASSWORD
value: "123"
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
hostPath:
path: /data/db
---
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
selector:
app: mysql // 指定pod的标签
ports:
- protocol: TCP
port: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: http
env:
- name: WORDPRESS_DB_HOST
value: mysql
- name: WORDPRESS_DB_USER
value: wp-
- name: WORDPRESS_DB_PASSWORD
value: "123"
- name: WORDPRESS_DB_NAME
value: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
volumes:
- name: wordpress-persistent-storage
hostPath:
path: /data/wordpress
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
spec:
type: NodePort
selector:
app: wordpress
ports:
- name: http
protocol: TCP
port: 80
targetPort: http
wordpress才分3个
apiVersion: apps/v1
kind: Deployment
metadata:
name: php-server
labels:
name: php-server
spec:
replicas: 1
selector:
matchLabels:
app: php-server
template:
metadata:
labels:
app: php-server
spec:
containers:
- name: php-server
image: php:0.1
imagePullPolicy: IfNotPresent
volumeMounts:
- mountPath: /var/www/html/
name: nginx-data
ports:
- containerPort: 9000
volumes:
- name: nginx-data
hostPath:
path: /root/k8s/nmp/html
---
apiVersion: v1
kind: Service
metadata:
name: php
spec:
ports:
- name: php
port: 9000
protocol: TCP
targetPort: 9000
selector:
app: php-server
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-php
spec:
selector:
matchLabels:
app: nginx-php
replicas: 1
template:
metadata:
labels:
app: nginx-php
spec:
containers:
- name: nginx-php
image: nginx:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
volumeMounts:
- name: nginx-data
mountPath: /usr/share/nginx/html
- name: nginx-conf
mountPath: /etc/nginx/conf.d/
volumes:
- name: nginx-data
hostPath:
path: /root/k8s/nmp/html
- name: nginx-conf
hostPath:
path: /root/k8s/nmp/conf
---
apiVersion: v1
kind: Service
metadata:
name: nginx-php
spec:
type: NodePort
ports:
- name: nginx
port: 80
protocol: TCP
targetPort: 80
nodePort: 30003
selector:
app: nginx-php
网络资源in
[root@master-1 ai]# cat wordpress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql01
template:
metadata:
labels:
app: mysql01
spec:
containers:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "123"
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_USER
value: wp-
- name: MYSQL_PASSWORD
value: "123"
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
hostPath:
path: /data/db
---
apiVersion: v1
kind: Service
metadata:
name: mysql
spec:
selector:
app: mysql01
ports:
- protocol: TCP
port: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress:latest
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: http
env:
- name: WORDPRESS_DB_HOST
value: mysql
- name: WORDPRESS_DB_USER
value: wp-
- name: WORDPRESS_DB_PASSWORD
value: "123"
- name: WORDPRESS_DB_NAME
value: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
resources:
requests:
cpu: 200m
volumes:
- name: wordpress-persistent-storage
hostPath:
path: /data/wordpress
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
spec:
type: ClusterIP
selector:
app: wordpress
ports:
- name: http
protocol: TCP
port: 80
targetPort: http
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: welcom-in
spec:
rules:
- host: www.zls.com
http:
paths:
- path: /
pathType: ImplementationSpecific
backend:
service:
name: wordpress
port:
number: 80
标签:name,value,wordpress,mysql,spec,metadata
From: https://www.cnblogs.com/xiutai/p/17749247.html