Get the App
SLTechnology News&Howtos  ›  Servers  › 

How does K8s run a wordpress?

Shulou Source: shulou.com Published: 2022-05-31 23:27:02 09月22日 Update

This article introduces the relevant knowledge of "how to run a wordpress in K8s". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

K8s deployment wordpress official example method

It is easy to use K8s to run a wordpress, but it is difficult and difficult to say that the basic requirements are relatively high, which involves Service,persistentVolumeClaim,volumes

According to the tutorial, it only takes a few lines of code to do it.

First, create a kustomization.yaml file with the following contents

SecretGenerator:-name: mysql-pass literals:-password=123456resources:-mysql-deployment.yaml-wordpress-deployment.yaml# download two configuration files curl-LO https://k8s.io/examples/application/wordpress/mysql-deployment.yamlcurl-LO https://k8s.io/examples/application/wordpress/wordpress-deployment.yaml# and finally run kubectl apply-k. # to view the exposed IPkubectl get services wordpress

About kustomize

To put it simply, one tool reduces the workload of maintaining multiple sets of environment yaml

Pain points solved by kustomize

In general, there will be multiple sets of deployment environment: development environment, test environment, production environment, multiple sets of environment means that there are multiple sets of K8S application resources YAML. However, there are only minor configuration differences among so many sets of YAML, such as different image versions and different Label, and YAML in these different environments often lead to configuration errors due to human negligence. Furthermore, YAML maintenance for multiple environments is usually done by copying the YAML in one environment and modifying the differences. Some application management tools such as Helm require additional learning of DSL syntax. To sum up, there are many sets of applications in K8s environment, and the following problems are often encountered:

How to manage Kubernetes YAML resources of applications in different environments or different teams how to manage small differences in different environments in some way, so that resource configuration can be reused, reduce the workload of copy and change, how to simplify the process of maintaining applications, there is no need to learn additional template syntax Kustomize solves the above problems in the following ways:

Kustomize maintains application configuration in different environments through Base & Overlays (explained later). Kustomize uses patch to reuse Base configuration, and implements resource reuse in the part where Overlay describes the difference between Overlay and Base application configuration. Kustomize manages Kubernetes native YAML files and does not need to learn additional DSL syntax.

Be careful

Since the official service type is LoadBalancer, this is only valid for deployment to the public cloud. If you use the self-built k8s, you can use NodePort's service to provide a reference example.

ApiVersion: v1kind: Servicemetadata: name: service-wordpress labels: app: wordpressspec: selector: app: wordpress tier: frontend type: NodePort # service type ports:-port: 80 # by default, `targetPort` is set to the same value as the `port` field for convenience. NodePort: 30012 # specifies the port of the bound node (the default value range is 30000-32767). If it is not specified, it will be assigned by default targetPort: 80 "how to run a wordpress in K8s". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Environment applications multiple sets configuration differences ways differences resources learning management content files syntax reuse tiny examples official workload tools situation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker vpn MariaDB Shulou Tech Info macOS