文章目录
- 创建命名空间 kubectl create namespace wordpress
- 创建配置文件 wordpress-db.yaml文件 [数据库]
- 启动 kubectl apply -f wordpress-db.yaml
- 创建wordpress配置文件 wordpress.yaml
创建命名空间 kubectl create namespace wordpress
[root@manager-node wordpress]# kubectl create namespace wordpress
namespace/wordpress created
[root@manager-node wordpress]#
创建配置文件 wordpress-db.yaml文件 [数据库]
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: mysql-deploy
namespace: wordpress
labels:
app: mysql
spec:
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.6
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3306
name: dbport
env:
- name: MYSQL_ROOT_PASSWORD
value: rootPassW0rd
- 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:
name: mysql
namespace: wordpress
spec:
selector:
app: mysql
ports:
- name: mysqlport
protocol: TCP
port: 3306
targetPort:
启动 kubectl apply -f wordpress-db.yaml
[root@manager-node wordpress]# ls -la
total 4
drwxr-xr-x. 2 root root 31 Jan 13 13:45 .
drwxr-xr-x. 3 root root 23 Jan 13 13:44 ..
-rw-r--r--. 1 root root 973 Jan 13 13:45 wordpress-db.yaml
[root@manager-node wordpress]# pwd
/root/demo/clusterip-demo/wordpress
[root@manager-node wordpress]# kubectl apply -f wordpress-db.yaml
deployment.apps/mysql-deploy created
service/mysql created
[root@manager-node wordpress]#
[root@manager-node wordpress]# kubectl get pods -n wordpress -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mysql-deploy-78cd6964bd-8mqpg 1/1 Running 0 3m28s 192.168.101.55 worker01-node <none> <none>
[root@manager-node wordpress]#
启动的时候 可能会稍微慢点,需要一点时间去创建pod
** 查看进度 kubectl describe pod mysql-deploy-78cd6964bd-8mqpg -n wordpress**
[root@manager-node wordpress]# kubectl describe pod mysql-deploy-78cd6964bd-8mqpg -n wordpress
Name: mysql-deploy-78cd6964bd-8mqpg
Namespace: wordpress
Priority: 0
PriorityClassName: <none>
Node: worker01-node/10.0.2.15
Start Time: Mon, 13 Jan 2020 14:08:29 +0000
Labels: app=mysql
pod-template-hash=78cd6964bd
Annotations: cni.projectcalico.org/podIP: 192.168.101.55/32
Status: Running
IP: 192.168.101.55
Controlled By: ReplicaSet/mysql-deploy-78cd6964bd
Containers:
mysql:
Container ID: docker://f23577ebc0603015c8dc101ba156ca373ead0d112cbbe5235f09b0e975dfa03b
Image: mysql:5.6
Image ID: docker-pullable://mysql@sha256:82a505551c0243ca04df445f1287b2c4da3b23463b1a9c0bc2b2476760179950
Port: 3306/TCP
Host Port: 0/TCP
State: Running
Started: Mon, 13 Jan 2020 14:11:04 +0000
Ready: True
Restart Count: 0
Environment:
MYSQL_ROOT_PASSWORD: rootPassW0rd
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
Mounts:
/var/lib/mysql from db (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-v764r (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
db:
Type: HostPath (bare host directory volume)
Path: /var/lib/mysql
HostPathType:
default-token-v764r:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-v764r
Optional: false
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute for 300s
node.kubernetes.io/unreachable:NoExecute for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 4m59s default-scheduler Successfully assigned wordpress/mysql-deploy-78cd6964bd-8mqpg to worker01-node
Normal Pulling 4m58s kubelet, worker01-node Pulling image "mysql:5.6"
Normal Pulled 2m25s kubelet, worker01-node Successfully pulled image "mysql:5.6"
Normal Created 2m25s kubelet, worker01-node Created container mysql
Normal Started 2m24s kubelet, worker01-node Started container mysql
[root@manager-node wordpress]#
创建wordpress配置文件 wordpress.yaml
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: wordpress-deploy
namespace: wordpress
labels:
app: wordpress
spec:
template:
metadata:
labels:
app: wordpress
spec:
containers:
- name: wordpress
image: wordpress
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
name: wdport
env:
- name: WORDPRESS_DB_HOST
value: 192.168.1.133:3306
- name: WORDPRESS_DB_USER
value: wordpress
- name: WORDPRESS_DB_PASSWORD
value: wordpress
---
apiVersion: v1
kind: Service
metadata:
name: wordpress
namespace: wordpress
spec:
type: NodePort
selector:
app: wordpress
ports:
- name: wordpressport
protocol: TCP
port: 80
targetPort:
[root@manager-node wordpress]# kubectl apply -f wordpress.yaml
deployment.apps/wordpress-deploy created
service/wordpress created
[root@manager-node wordpress]#
[root@manager-node wordpress]# kubectl get pods -n wordpress -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
mysql-deploy-78cd6964bd-8mqpg 1/1 Running 0 37m 192.168.101.55 worker01-node <none> <none>
wordpress-deploy-6867948b7b-vk9n7 1/1 Running 0 7m40s 192.168.101.56 worker01-node <none> <none>
[root@manager-node wordpress]#
这个有点耗时,这里注意下
[root@manager-node wordpress]# kubectl get svc -n wordpress -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
mysql ClusterIP 10.109.42.210 <none> 3306/TCP 31m app=mysql
wordpress NodePort 10.97.184.238 <none> 80:31629/TCP 2m app=wordpress
[root@manager-node wordpress]#