In this tutorial we will create a Deployment as an example, demonstrating how to deploy Wordpress web application to KubeSphere, which is based on the last guide Deploy a MySQL Application. The connection password between WordPress and MySQL will be created and saved as a ConfigMap.
project-regular
and enter into the corresponding project.About 15 minutes.
1.1. Enter the project, navigate to Configuration Center → ConfigMaps, then choose Create ConfigMap.
1.2. Fill in the basic information, e.g. Name : wordpress-configmap
. Then choose Next when you're done.
1.3. ConfigMap parameter is composed of a set of key-value pairs, fill in the blanks with the following values and select Create.
2.1. Navigate to Volumes, and click Create. Then fill in the basic information, e.g. Name : wordpress-pvc
, choose Next when you're done.
2.2. Volume settings depends on your storage class configuration, local volume is set to the default storage class if used all-in-one installation, its volume settings as below screenshot:
2.3. We simply keep the default label settings as app: wordpress-pvc
, then choose Create.
2.4. when you redirect to the Volumes list, you will be able to see the volume wordpress-pvc
has been created successfully.
Reminder: The volume will display
Pending
if it is not yet mounted, actually it is normal since local doesn't suppor Dynamic Volume Provisioning. This volume will change toBound
when it is mounted to the workload.
Navigate to Workloads → Deployments, then click Create.
Fill in the basic information, e.g. Name : wordpress
. Then choose Next when you're done.
5.1. Click Add Container, Container Name can be customized by the user, fill in the image with wordpress:4.8-apache
, leave the CPU and Memory at their default values. Click Advanced Options.
5.2. We'll simply set the Ports and Environmental Variables according to the following hints.
Ports:
Environmental Variables (It requires to create 2 environmental variables in this section)
WORDPRESS_DB_PASSWORD
wordpress-configmap
WORDPRESS_DB_PASSWORD
Then select Add Environmental Variable, and fill in the name/value:
Choose Save when you're done.
5.3. No need to modify the Replicas and Horizontal Pod Autoscaling, For Update Strategy you can keep RollingUpdate
which is a recommended strategy. Then click Next.
6.1. Choose Add Existing Volume, select the wordpress-pvc
which was created in Step 2.
6.2. Set the Mount Path to /var/www/html
and select ReadAndWrite
. Then click Save and select Next when you're done.
7.1. We simply keep the default label settings as app: wordpress
. There is no need to set Node Selector in this demo, you can choose Create directly.
7.2. You will be able to see the WordPress Deployment displays "updating" since this process requires a series of operations such as pulling a Docker image of the specified tag, creating a container, and connecting the MySQL database. Normally, it will change to "running" at around 1 min.
8.1. Navigate to Network & Service → Service, choose Create.
8.2. Fill in the basic information, e.g. Name : wordpress-service
. Then choose Next when you're done.
8.3. Reference the following information to complete the Service Settings:
wordpress
and click Save.Ports:
8.4. We simply keep the default label settings as app: wordpress-service
, then choose Next.
8.5. We are going to expose this service via Route (Ingress), so leave the Access Method at None
. Then click Create, the wordpress-service
has been created successfully.
9.1. Navigate to Network & Service → Routes and choose Create Route.
9.2. Fill in the basic information, e.g. Name: wordpress-ingress
, click Next when you're done.
9.3. Choose Add Route Rule, set the Route Rule according to the following hints:
wordpress.demo.io
, wordpress service will be accessed via this hostname.http
(if select https please create the related certificates in secrets)Paths:
/
wordpress-service
80
9.4. Add a line of record ({$EIP} {$hostname}) to the your local hosts
file. For example, if the EIP of your KubeSphere is 139.198.16.160
and the hostname has been set to wordpress.demo.io
, then we need to add a line of record to /etc/hosts
as following:
139.198.16.160 wordpress.demo.io
9.5. Skip the Annotation, then keep the default label settings as app: wordpress-ingress
.
9.6. Click Create, the wordpress-ingress
will be created successfully.
10.1. Navigate to Project-Settings → Internet Access, then click Set Gateway.
10.2. Make sure the Access Method is set to NodePort
, then choose Save.
Reminder: LoadBalancer is required Cloud provider's LB plugin integration and support, QingCloud LoadBalancer plugin is in development and will coming soon.
10.3. It will generate 2 node ports, represent http and https respectively, e.g. 31499 and 32646.
Note: If you want to expose the service externally, you might need to bind the EIP and configure port forwarding. Then add the corresponding port (e.g. 31499) to the firewall rules to ensure that the external network traffic can pass through the port. In that case, external access will be available.
At this point, WordPress is exposed to the outside by the Ingress, thus we can access it in your browser via {$hostname}:{$NodePort}
i.e. http://wordpress.demo.io:30517
since we selected http protocol previously.
Hope you could be familiar with the basic features of Deployments and StatefulSets right now, see the Deployments and StatefulSets for the details.