Creating applications from YAML

If you are proficient in YAML syntax and prefer to use configurations not defined in forms or templates, you can opt for the one-click YAML creation method. This approach allows for more flexible configuration of basic information and resources for your native application.

Precautions

When both Linux and Windows nodes exist in the cluster, to prevent scheduling the application on incompatible nodes, you must configure node selection. For example:

spec:
    spec:
      nodeSelector:
        kubernetes.io/os: linux

Prerequisites

Ensure the images defined in the YAML can be pulled within the current cluster. You can verify this using the docker pull command.

Procedure

  1. Container Platform, and navigate to Application > Applications.

  2. Click Create.

  3. Select the Create from YAML.

  4. Complete the configuration and click Create.

  5. The corresponding Deployment can be viewed on the Details page.

# webapp-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: webapp
  labels:
    app: webapp
    env: prod
spec:
  replicas: 3
  selector:
    matchLabels:
      app: webapp
  template:
    metadata:
      labels:
        app: webapp
        tier: frontend
    spec:
      containers:
      - name: webapp
        image: nginx:1.25-alpine
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: "100m"
            memory: "128Mi"
          limits:
            cpu: "250m"
            memory: "256Mi"
---
# webapp-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: webapp-service
spec:
  selector:
    app: webapp
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP
```yaml