Skip to content

Commit

Permalink
更新wordpress示例
Browse files Browse the repository at this point in the history
  • Loading branch information
cnych committed Dec 18, 2019
1 parent 1160e58 commit 3ce13f4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
48 changes: 31 additions & 17 deletions docs/31.部署 Wordpress 示例.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
args: # 新版本镜像有更新,需要使用下面的认证插件环境变量配置才会生效
- --default_authentication_plugin=mysql_native_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
ports:
- containerPort: 3306
name: dbport
Expand Down Expand Up @@ -80,14 +84,17 @@ $ kubectl describe pod wordpress -n blog
第一步,创建一个`MySQL`的`Deployment`对象:(wordpress-db.yaml)
```yaml
---
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deploy
namespace: blog
labels:
app: mysql
spec:
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
Expand All @@ -97,6 +104,10 @@ spec:
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
args:
- --default_authentication_plugin=mysql_native_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
ports:
- containerPort: 3306
name: dbport
Expand Down Expand Up @@ -160,17 +171,19 @@ Events: <none>
```
可以看到`Endpoints`部分匹配到了一个`Pod`,生成了一个`clusterIP`:`10.98.27.19`,现在我们是不是就可以通过这个`clusterIP`加上定义的3306端口就可以正常访问我们这个`mysql`服务了。


第二步. 创建`Wordpress`服务,将上面的`wordpress`的`Pod`转换成`Deployment`对象:(wordpress.yaml)
```yaml
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-deploy
namespace: blog
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
template:
metadata:
labels:
Expand Down Expand Up @@ -331,15 +344,17 @@ initContainers:

最后,我们把部署的应用整合到一个`YAML`文件中来:(wordpress-all.yaml)
```yaml
---
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deploy
name: mysql
namespace: blog
labels:
app: mysql
spec:
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
Expand All @@ -348,6 +363,10 @@ spec:
containers:
- name: mysql
image: mysql:5.7
args:
- --default_authentication_plugin=mysql_native_password
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
ports:
- containerPort: 3306
name: dbport
Expand Down Expand Up @@ -383,17 +402,18 @@ spec:
port: 3306
targetPort: dbport
---
apiVersion: apps/v1beta1
apiVersion: apps/v1
kind: Deployment
metadata:
name: wordpress-deploy
name: wordpress
namespace: blog
labels:
app: wordpress
spec:
revisionHistoryLimit: 10
selector:
matchLabels:
app: wordpress
minReadySeconds: 5
strategy:
type: RollingUpdate
Expand Down Expand Up @@ -423,11 +443,6 @@ spec:
value: wordpress
- name: WORDPRESS_DB_PASSWORD
value: wordpress
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 3
periodSeconds: 3
readinessProbe:
tcpSocket:
port: 80
Expand All @@ -436,7 +451,7 @@ spec:
resources:
limits:
cpu: 200m
memory: 200Mi
memory: 256Mi
requests:
cpu: 100m
memory: 100Mi
Expand All @@ -457,7 +472,6 @@ spec:
port: 80
nodePort: 32255
targetPort: wdport
```

我们这里主要是针对的`wordpress`来做的提高稳定性的方法,如何对`mysql`提高一些稳定性呢?大家下去可以试一试,我们接下来会和大家讲解`mysql`这类有状态的应用在`Kubernetes`当中的使用方法。
Expand Down
2 changes: 1 addition & 1 deletion jenkins-demo
Submodule jenkins-demo updated from 716a81 to d3f20c

0 comments on commit 3ce13f4

Please sign in to comment.