RHCA之路---EX280(5)

RHCA之路—EX280(5)

1. 题目

RHCA之路---EX280(5)_第1张图片
Using the example files from the wordpress directory under
http://materials.example.com/exam280/wordpress create a WordPress application in the farm project
For permanent storage use the NFS shares /exports/wordpress and /exports/mysql from services.lab.example.com.
Use the files from http://materials.example.com/exam280/wordpress for the volumes
For the WordPress pod, use the Docker image from
http://materials.example.com/exam280/wordpress.tar
(Note: it is normal if the WordPress pod initially restarts a couple of times due to permaission issues)
For the MySQL pod use the Docker image rhscl/mysql-57-rhel7
Once deployed,the application must be reachable at the following address:
http://blog.apps.lab.example.com
Finally, complete the WordPress installation by setting ayumi as the admin user with password redhat and [email protected] for the email address
Set the blog name to EX280 Blog
Create your first post with title faber est quisque fortunae suae.
The text in the post does not matter

2. 解题

2.1 切换项目

切记一定不要漏这步

[root@master php-helloworld]# oc project farm
Now using project "farm" on server "https://master.lab.example.com".
[root@master php-helloworld]# mkdir ~/farm
[root@master php-helloworld]# cd ~/farm
[root@master farm]# oc projects
You have access to the following projects and can switch between them with 'oc project ':

    default
    ditto
  * farm
    kube-public
    kube-service-catalog
    kube-system
    logging
    management-infra
    openshift
    openshift-ansible-service-broker
    openshift-infra
    openshift-node
    openshift-template-service-broker
    openshift-web-console
    rome
    samples
    shrimp

Using project "farm" on server "https://master.lab.example.com".

2.2 下载模板文件

wget http://materials.example.com/exam280/wordpress/pv.yaml
wget http://materials.example.com/exam280/wordpress/pvc.yaml
wget http://materials.example.com/exam280/wordpress/pod-mysql.yaml
wget http://materials.example.com/exam280/wordpress/pod-wordpress.yaml
wget http://materials.example.com/exam280/wordpress/service-mysql.yaml
wget http://materials.example.com/exam280/wordpress/service-wp.yaml
cp pv.yaml mypv.yaml
cp pvc.yaml mypvc.yaml
cp pv.yaml wppv.yaml
cp pvc.yaml wppvc.yaml

2.3 配置mysql

2.3.1 mypv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mypv
spec:
  capacity:
    storage: 3Gi
  accessModes:
  - ReadWriteOnce
  nfs:
    path: /exports/mysql
    server: services.lab.example.com
  persistentVolumeReclaimPolicy: Recycle

2.3.2 mypvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: dbclaim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi

2.3.3 pod-mysql.yaml

apiVersion: v1
kind: Pod
metadata:
  name: mysql
  labels:
    name: mysql
spec:
  containers:
    - image: registry.lab.example.com/rhscl/mysql-57-rhel7:latest
      name: mysql
      env:
        - name: MYSQL_ROOT_PASSWORD
          value: redhat
        - name: MYSQL_USER
          value: tom
        - name: MYSQL_PASSWORD
          value: redhat
        - name: MYSQL_DATABASE
          value: blog
      ports:
        - containerPort: 3306
          name: mysql
      volumeMounts:
        - name: mysql-persistent-storage
          mountPath: /var/lib/mysql/data
  volumes:
    - name: mysql-persistent-storage
      persistentVolumeClaim:
        claimName: dbclaim

2.3.4 service-mysql.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    name: mysql
  name: mysql
spec:
  ports:
    # the port that this service should serve on
    - port: 3306
  # label keys and values that must match in order to receive traffic for this service
  selector:
    name: mysql

2.3.5 创建mysql

[root@master farm]# oc create -f mypv.yaml
persistentvolume "mypv" created
[root@master farm]# oc create -f mypvc.yaml
persistentvolumeclaim "dbclaim" created
[root@master farm]# oc create -f pod-mysql.yaml
pod "mysql" created
[root@master farm]# oc create -f service-mysql.yaml
service "mysql" created

2.4 配置wordpress

2.4.1 wordpress镜像准备

[root@master farm]# wget http://materials.example.com/exam280/wordpress.tar
--2023-09-04 15:49:32--  http://materials.example.com/exam280/wordpress.tar
Resolving materials.example.com (materials.example.com)... 172.25.254.254
Connecting to materials.example.com (materials.example.com)|172.25.254.254|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 419054592 (400M) [application/x-tar]
Saving to: ‘wordpress.tar’

100%[===========================================================================================================>] 419,054,592 70.6MB/s   in 5.7s

2023-09-04 15:49:38 (70.7 MB/s) - ‘wordpress.tar’ saved [419054592/419054592]

[root@master farm]# docker load -i wordpress.tar
2c40c66f7667: Loading layer [==================================================>] 129.3 MB/129.3 MB
ddd6dcab19ff: Loading layer [==================================================>] 204.7 MB/204.7 MB
f0c367fa8636: Loading layer [==================================================>] 3.584 kB/3.584 kB
0fd7a67d49b3: Loading layer [==================================================>] 7.699 MB/7.699 MB
53da01089a82: Loading layer [==================================================>] 10.24 kB/10.24 kB
3d2582fdede2: Loading layer [==================================================>] 9.728 kB/9.728 kB
315db89f9acb: Loading layer [==================================================>] 4.096 kB/4.096 kB
2da371244fc1: Loading layer [==================================================>]  7.68 kB/7.68 kB
354b4ef9664b: Loading layer [==================================================>] 13.01 MB/13.01 MB
adfd7c98cdf6: Loading layer [==================================================>] 4.096 kB/4.096 kB
8747705a74d9: Loading layer [==================================================>] 33.01 MB/33.01 MB
5a151fa4136e: Loading layer [==================================================>] 11.78 kB/11.78 kB
c8c6d352c96e: Loading layer [==================================================>] 4.608 kB/4.608 kB
fed26d7fe7b9: Loading layer [==================================================>]  6.04 MB/6.04 MB
4214911d5945: Loading layer [==================================================>] 4.608 kB/4.608 kB
6671cb9eb6b3: Loading layer [==================================================>] 7.168 kB/7.168 kB
562dd11ed871: Loading layer [==================================================>] 25.12 MB/25.12 MB
53e16fa1f104: Loading layer [==================================================>] 10.24 kB/10.24 kB
Loaded image: 192.168.122.250:5000/openshift/wordpress:latest
[root@master farm]# docker tag 192.168.122.250:5000/openshift/wordpress:latest registry.lab.example.com/openshift/wordpress:latest
[root@master farm]# docker push registry.lab.example.com/openshift/wordpress:latest
The push refers to a repository [registry.lab.example.com/openshift/wordpress]
53e16fa1f104: Pushed
562dd11ed871: Pushed
6671cb9eb6b3: Pushed
4214911d5945: Pushed
fed26d7fe7b9: Pushed
c8c6d352c96e: Pushed
5a151fa4136e: Pushed
8747705a74d9: Pushed
adfd7c98cdf6: Pushed
354b4ef9664b: Pushed
2da371244fc1: Pushed
315db89f9acb: Pushed
3d2582fdede2: Pushed
53da01089a82: Pushed
0fd7a67d49b3: Pushed
f0c367fa8636: Pushed
ddd6dcab19ff: Pushed
2c40c66f7667: Pushed
latest: digest: sha256:ca4cf4692b7bebd81f229942c996b1c4e6907d6733e977e93d671a54b8053a22 size: 4078

2.4.2 wppv.yaml

apiVersion: v1
kind: PersistentVolume
metadata:
  name: wppv
spec:
  capacity:
    storage: 4Gi
  accessModes:
  - ReadWriteOnce
  nfs:
    path: /exports/wordpress
    server: services.lab.example.com
  persistentVolumeReclaimPolicy: Recycle

2.4.3 wppvc.yaml

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: blogclaim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 4Gi

2.4.4 pod-wordpress.yaml

apiVersion: v1
kind: Pod
metadata:
  name: wordpress
  labels:
    name: wordpress
spec:
  containers:
    - image: registry.lab.example.com/openshift/wordpress:latest
      name: wordpress
      env:
        - name: WORDPRESS_DB_USER
          value: root
        - name: WORDPRESS_DB_PASSWORD
          value: redhat
        - name: WORDPRESS_DB_NAME
          value: blog
        - name: WORDPRESS_DB_HOST
          # this is the name of the mysql service fronting the mysql pod in the same namespace
          # expands to mysql..svc.cluster.local  - where  is the current namespace
          value: mysql
      ports:
        - containerPort: 80
          name: wordpress
      volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
  volumes:
    - name: wordpress-persistent-storage
      persistentVolumeClaim:
       claimName: blogclaim

2.4.5 service-wp.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    name: wpfrontend
  name: wpfrontend
spec:
  ports:
    # the port that this service should serve on
    - port: 80
      targetPort: 80
  # label keys and values that must match in order to receive traffic for this service
  selector:
    name: wordpress

2.4.6 创建wordpress

[root@master farm]# oc create -f wppv.yaml
persistentvolume "wppv" created
[root@master farm]# oc create -f wppvc.yaml
persistentvolumeclaim "blogclaim" created
[root@master farm]# oc create -f pod-wordpress.yaml
pod "wordpress" created
[root@master farm]# oc create -f service-wp.yaml
service "wpfrontend" created

2.4.7 创建wordpress路由

[root@master farm]# oc expose svc wpfrontend --hostname=blog.apps.lab.example.com
route "wpfrontend" exposed

2.5 配置wordpress

RHCA之路---EX280(5)_第2张图片
RHCA之路---EX280(5)_第3张图片
RHCA之路---EX280(5)_第4张图片
RHCA之路---EX280(5)_第5张图片

3. 确认

RHCA之路---EX280(5)_第6张图片
可以看到这个页面基本没问题了
RHCA之路---EX280(5)_第7张图片

你可能感兴趣的:(Linux,rhca,linux,RHCA)