1、创建MySQL Pod,使用环境变量初始化管理员密码、创建一个普通用户和一个数据库;
kubectl create deployment mysql --image mysql:8.0 --dry-run=client -o yaml > mysql1.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: mysql
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mysql
spec:
containers:
- image: mysql:8.0
name: mysql
env:
- name: MYSQL_RANDOM_ROOT_PASSWORD
value: '1'
- name: MYSQL_DATABASE
value: 'wordpress'
- name: MYSQL_USER
value: 'wpuser'
resources: {}
status: {}
root@k8s-master01:~/wordpress#kubectl apply -f mysql1.yaml
2、创建wordpress Pod,使用环境变量对接到MySQL,并wordpress初始化;
kubectl create deployment wordpress --image wordpress:5.7 --dry-run=client -o yaml > wordpress.yaml
root@k8s-master01:~/wordpress# vim wordpress.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: wordpress
name: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: wordpress
spec:
containers:
- image: wordpress:5.7
name: wordpress
# livenessProbe:
#httpGet:
# path: '/'
# scheme: HTTP
env:
- name: WORDPRESS_DB_HOST
value: '10.244.3.56'
- name: WORDPRESS_DB_NAME
value: 'wordpress'
- name: WORDPRESS_DB_USER
value: 'wpuser'
- name: WORDPRESS_DB_PASSWORD
value: '123456'
ports:
- containerPort: 80
hostPort: 8080
resources: {}
status: {}
root@k8s-master01:~/wordpress#kubectl apply -f wordpress.yaml
3、为以上Pod设定livenessProbe, readinessProbe, resource limits和resource requests。
#mysql
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: mysql
name: mysql
spec:
replicas: 1
selector:
matchLabels:
app: mysql
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: mysql
spec:
containers:
- image: mysql:8.0
name: mysql
readinessProbe:
exec:
command: ['/bin/sh', '-c', '/usr/bin/mysql -u wpuser -p123456']
initialDelaySeconds: 10
timeoutSeconds: 5
periodSeconds: 5
failureThreshold: 10
livenessProbe:
tcpSocket:
port: 3306
initialDelaySeconds: 10
timeoutSeconds: 5
periodSeconds: 5
failureThreshold: 5
env:
- name: MYSQL_RANDOM_ROOT_PASSWORD
value: '1'
- name: MYSQL_DATABASE
value: 'wordpress'
- name: MYSQL_USER
value: 'wpuser'
resources:
requests:
memory: "64Mi"
cpu: "200m"
limits:
memory: "512Mi"
cpu: "1"
status: {}
#wordpress
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: wordpress
name: wordpress
spec:
replicas: 1
selector:
matchLabels:
app: wordpress
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: wordpress
spec:
containers:
- image: wordpress:5.7
name: wordpress
livenessProbe:
httpGet:
path: '/'
port: 80
scheme: HTTP
intialDelaySeconds: 3
timeoutSeconds: 2
readnessProbe:
httpGet:
path: '/'
port: 80
scheme: HTTP
intialDelaySeconds: 15
timeoutSeconds: 2
restartPolicy: Always
env:
- name: WORDPRESS_DB_HOST
value: '10.244.3.56'
- name: WORDPRESS_DB_NAME
value: 'wordpress'
- name: WORDPRESS_DB_USER
value: 'wpuser'
- name: WORDPRESS_DB_PASSWORD
value: '123456'
ports:
- containerPort: 80
hostPort: 8080
resources:
requests:
memory: "90Mi"
cpu: "1"
limits:
memory: "300Mi"
cpu: "1
status: {}
评论(0)