k8s部署wordpress应用
一、编译wordpress.yaml文件kind: Namespacemetadata:name: wordpress---apiVersion: v1kind: Podmetadata:name: wordpressnamespace: wordpresslabels:app: wordpressspec:containers:- name: wordpressimage: wordpressp
·
一、编译wordpress.yaml文件
kind: Namespace
metadata:
name: wordpress
---
apiVersion: v1
kind: Pod
metadata:
name: wordpress
namespace: wordpress
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress
ports:
- containerPort: 80
name: wdport
resources:
limits: ##资源的限制
cpu: "20m"
memory: 512Mi
requests: ###给pod分配的资源
cpu: "10m"
memory: 128Mi
env:
- name: WORDPRESS_DB_HOST
value: 127.0.0.1:3306
- name: WORDPRESS_DB_USER
value: wordpress
- name: WORDPRESS_DB_PASSWORD
value: wordpress
imagePullPolicy: IfNotPresent
- name: mysql
image: mysql:5.7
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
name: dbport
resources:
limits: ##资源的限制
cpu: "20m"
memory: 512Mi
requests: ###给pod分配的资源
cpu: "10m"
memory: 128Mi
env:
- name: MYSQL_ROOT_PASSWORD
value: dayi123
- name: MYSQL_DATABASE
value: wordpress
- name: MYSQL_USER
value: wordpress
- name: MYSQL_PASSWORD
value: wordpress
volumeMounts:
- name: db
mountPath: /var/lib/mysql
volumes:
- name: db
hostPath:
path: /var/lib/mysql
---
apiVersion: v1
kind: Service
metadata:
labels:
app: wordpress
name: wp-svc
namespace: wordpress
spec:
ports:
- port: 8081
protocol: TCP
targetPort: 80
selector:
app: wordpress
type: NodePort
二、启动wordpress
[root@node1 yaml]# kubectl apply -f wordpress.yaml
namespace/wordpress created
pod/wordpress created
service/wp-svc created
[root@node1 yaml]# kubectl get po -n wordpress -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
wordpress 2/2 Running 0 13s 172.25.135.59 node3 <none> <none>
[root@node1 yaml]# kubectl get svc -n wordpress -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
wp-svc NodePort 10.96.156.241 <none> 8081:31450/TCP 31s app=wordpress
三、界面访问
ip+svc端口
更多推荐
已为社区贡献16条内容
所有评论(0)