To build a wordpress app using K8S, it is easy and difficult. It requires a lot of basics, including Service, persistentVolumeClaim and volumes

The easy part is that officials have examples

Follow the tutorial and it only takes a few lines of code

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

secretGenerator:
  - name: mysql-pass
    literals:
      - password=123456
resources:
  - mysql-deployment.yaml
  - wordpress-deployment.yaml
Copy the code
Download two configuration files
curl -LO https://k8s.io/examples/application/wordpress/mysql-deployment.yaml
curl -LO https://k8s.io/examples/application/wordpress/wordpress-deployment.yaml
# last run
kubectl apply -k .
# View exposed IP
kubectl get services wordpress
Copy the code

About kustomize

A simple tool to reduce the workload of maintaining multiple sets of YAML environments

Blog.csdn.net/easylife206…

www.jianshu.com/p/837d7ae77…

Kustomize addresses pain points

Generally, applications have multiple deployment environments: development environment, test environment, and production environment. Multiple environments mean multiple sets of K8S application resource YAML. However, there are only minor configuration differences among these sets of YAMLS, such as different mirrored versions and labels, which often lead to configuration errors due to human negligence. Furthermore, YAML maintenance for multiple environments is usually done by copying YAML from one environment and making changes to the differences. Application management tools such as Helm require additional learning of DSL syntax. To sum up, there are multiple applications in K8S environment, and the following problems are often encountered:

How to manage Kubernetes YAML resources for applications in different environments or teams how to manage small differences in different environments in a way that makes resource configurations reusable and reduces copy and change how to simplify the process of maintaining applications No additional learning of template syntax Kustomize solves this problem in several ways:

Kustomize maintains application Settings for different environments using Base & Overlays (described below) kustomize uses patch to reuse Base Settings In addition, in the part of Overlay description and Base application configuration differences to realize resource reuse kustomize management are all Kubernetes native YAML files, there is no need to learn additional DSL syntax

Pay attention to

Since the official service type used is LoadBalancer, this is only valid for deployment to the public cloud. If you are using your own K8S, you can use NodePort’s service to provide a reference example

apiVersion: v1
kind: Service
metadata:
  name: service-wordpress
  labels:
    app: wordpress
spec:
  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 # Specify the port to be bound to the node (default: 30,000-32767). If this is not specified, the port will be assigned by default
      targetPort: 80
Copy the code

reference

Kubernetes. IO/docs/tutori…