Introduction

Many times, due to resource constraints in development environments, we have to divide our project environments into Docker Compose and Kubernetes, so that we don’t need to run a complete Kubernetes service in the local development environment! But this also creates some extra work, such as maintaining both docker-compose.yaml and Kubernetes manifests.yaml files, or even HELM configuration files, etc.

Score was created to solve this problem. It uses a custom YAML Specification to describe containers, services, resources, and other configurations, and then converts the score.yaml configuration into YAML configurations for the corresponding platforms through the appropriate CLI!

Score’s Slogan:

Configure once. Deploy anywhere. From local to prod.

Installation

brew install score-spec/tap/score-k8s
brew install score-spec/tap/score-helm
brew install score-spec/tap/score-compose

For other operating systems or platforms, please refer to the official documentation.

Trial

Initialize a Score project:

score-k8s init
score-compose init
tree -a
.
├── .score-compose
│   ├── mounts
│   ├── state.yaml
│   └── zz-default.provisioners.yaml
├── .score-k8s
│   ├── state.yaml
│   └── zz-default.provisioners.yaml
└── score.yaml

4 directories, 5 files

Orchestration

Edit the score.yaml file generated by Score CLI. For example, I wrote a Nginx example:

apiVersion: score.dev/v1b1

metadata:
  name: ects

containers:
  nginx:
    image: nginx:latest
    variables:
      TZ: Asia/Shanghai

service:
  ports:
    http:
      port: 80
      targetPort: 80
    https:
      port: 443
      targetPort: 443

resources: {}

For more score.yaml Specifications, please refer to the official documentation.

Generate Configuration

score-k8s generate score.yaml
INFO: Added score file to project
INFO: Primed resources
INFO: Loaded provisioners
INFO: Persisted state file
INFO: Wrote 2 manifests to manifests buffer for workload 'ects'
INFO: Wrote manifests to 'manifests.yaml'

score-compose generate score.yaml
INFO: Loaded state directory with docker compose project 'nginx'
INFO: Validated workload 'ects'
INFO: Successfully loaded 12 resource provisioners
INFO: Converting workload 'ects' to Docker compose

tree -a
.
├── .score-compose
│   ├── mounts
│   ├── state.yaml
│   └── zz-default.provisioners.yaml
├── .score-k8s
│   ├── state.yaml
│   └── zz-default.provisioners.yaml
├── compose.yaml
├── manifests.yaml
└── score.yaml

4 directories, 7 files

Finally, two YAML configuration files, compose.yaml and manifests.yaml, were generated as follows:

compose.yaml file content:

name: nginx
services:
    ects-nginx:
        annotations:
            compose.score.dev/workload-name: ects
        environment:
            TZ: Asia/Shanghai
        hostname: ects
        image: nginx:latest

manifests.yaml file content:

---
apiVersion: v1
kind: Service
metadata:
    annotations:
        k8s.score.dev/workload-name: ects
    creationTimestamp: null
    labels:
        app.kubernetes.io/instance: ects-38d609b839
        app.kubernetes.io/managed-by: score-k8s
        app.kubernetes.io/name: ects
    name: ects-svc
spec:
    ports:
        - name: http
          port: 80
          protocol: TCP
          targetPort: 80
        - name: https
          port: 443
          protocol: TCP
          targetPort: 443
    selector:
        app.kubernetes.io/instance: ects-38d609b839
status:
    loadBalancer: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
    annotations:
        k8s.score.dev/workload-name: ects
    creationTimestamp: null
    labels:
        app.kubernetes.io/instance: ects-38d609b839
        app.kubernetes.io/managed-by: score-k8s
        app.kubernetes.io/name: ects
    name: ects
spec:
    replicas: 1
    selector:
        matchLabels:
            app.kubernetes.io/instance: ects-38d609b839
    strategy: {}
    template:
        metadata:
            annotations:
                k8s.score.dev/workload-name: ects
            creationTimestamp: null
            labels:
                app.kubernetes.io/instance: ects-38d609b839
                app.kubernetes.io/managed-by: score-k8s
                app.kubernetes.io/name: ects
        spec:
            containers:
                - env:
                    - name: TZ
                      value: Asia/Shanghai
                  image: nginx:latest
                  name: nginx
                  resources: {}
status: {}

Conclusion

Currently, Score is still in its early stages, and its supported configurations are relatively weak compared to docker-compose.yaml and Kubernetes’ manifests.yaml, unable to fully describe some features supported by each platform!

However, the project has entered the CNCF sandbox for incubation, and it is believed that it will become more and more complete in the future, greatly improving the work efficiency of YAML developers!

I hope this is helpful, Happy hacking…