Specification

Resources

Provisioner

Service


score-backend.yaml (view on GitHub) :

apiVersion: score.dev/v1b1
metadata:
  name: backend
containers:
  my-container:
    image: busybox
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo Hello Backend; sleep 5; done"]

score-frontend.yaml (view on GitHub) :

apiVersion: score.dev/v1b1
metadata:
  name: frontend
containers:
  my-container:
    image: busybox
    command: ["/bin/sh"]
    args: ["-c", "while true; do echo $BACKEND_SVC; sleep 5; done"]
    variables:
      BACKEND_SVC: http://${resources.backend.name}
resources:
  backend:
    type: service


10-service.provisioners.yaml (view on GitHub) :

- uri: template://community-provisioners/static-service
  type: service
  description: Outputs the name of the Workload dependency if it exists in the list of Workloads.
  init: |
    name: {{ splitList "." .Id | last }}    
  outputs: |
    {{ $w := (index .WorkloadServices .Init.name) }}
    {{ if or (not $w) (not $w.ServiceName) }}{{ fail "unknown workload" }}{{ end }}
    name: {{ $w.ServiceName | quote }}    
  expected_outputs:
    - name

Initialize your local workspace, by importing a specific community provisioner:

score-commpose init --provisioners REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml

Note: you need to replace REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml by the actual provisioner file you want to use and import. More information here.

Get the provisioners definition:

score-compose provisioners list

Generate the platform specific manifests:

score-commpose generate score.yaml

See the resource outputs:

score-commpose resources list

You can run the following command on each resource listed with the previous command to get their outputs:

score-commpose resources get-outputs

Deploy the generated manifests:

docker compose up -d

See the running containers:

docker ps


10-service-with-netpol.provisioners.yaml (view on GitHub) :

- uri: template://community-provisioners/static-service-with-netpol
  type: service
  description: Outputs the name of the Workload dependency if it exists in the list of Workloads, and generate NetworkPolicies between them.
  init: |
    name: {{ splitList "." .Id | last }}    
  outputs: |
    {{ $w := (index .WorkloadServices .Init.name) }}
    {{ if or (not $w) (not $w.ServiceName) }}{{ fail "unknown workload" }}{{ end }}
    name: {{ .Init.name }}    
  expected_outputs: 
    - name
  manifests: |
    - apiVersion: networking.k8s.io/v1
      kind: NetworkPolicy
      metadata:
        name: {{ .Init.name }}-from-{{ .SourceWorkload }}-ingress
        {{ if ne .Namespace "" }}
        namespace: {{ .Namespace }}
        {{ end }}
      spec:
        podSelector:
          matchLabels:
            app.kubernetes.io/name: {{ .Init.name }}
        policyTypes:
          - Ingress
        ingress:
        - from:
          - podSelector:
              matchLabels:
                app.kubernetes.io/name: {{ .SourceWorkload }}
            namespaceSelector:
              matchLabels:
                kubernetes.io/metadata.name: {{ .Namespace | default "default" }}
          ports:
          {{- range $k, $port := (index .WorkloadServices .Init.name).Ports }}
          - protocol: TCP
            port: {{ $port.TargetPort }}
          {{- end }}
    - apiVersion: networking.k8s.io/v1
      kind: NetworkPolicy
      metadata:
        name: {{ .SourceWorkload }}-to-{{ .Init.name }}-egress
        {{ if ne .Namespace "" }}
        namespace: {{ .Namespace }}
        {{ end }}
      spec:
        podSelector:
          matchLabels:
            app.kubernetes.io/name: {{ .SourceWorkload }}
        policyTypes:
          - Egress
        egress:
        - to:
          - podSelector:
              matchLabels:
                app.kubernetes.io/name: {{ .Init.name }}
            namespaceSelector:
              matchLabels:
                kubernetes.io/metadata.name: {{ .Namespace | default "default" }}
          ports:
          {{- range $k, $port := (index .WorkloadServices .Init.name).Ports }}
          - protocol: TCP
            port: {{ $port.TargetPort }}
          {{- end }}    

10-service.provisioners.yaml (view on GitHub) :

- uri: template://community-provisioners/static-service
  type: service
  description: Outputs the name of the Workload dependency if it exists in the list of Workloads.
  init: |
    name: {{ splitList "." .Id | last }}    
  outputs: |
    {{ $w := (index .WorkloadServices .Init.name) }}
    {{ if or (not $w) (not $w.ServiceName) }}{{ fail "unknown workload" }}{{ end }}
    name: {{ $w.ServiceName | quote }}    
  expected_outputs: 
    - name

Initialize your local workspace, by importing a specific community provisioner:

score-k8s init --provisioners REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml

Note: you need to replace REPLACE-ME-WITH-ACTUAL-PROVISIONER-FILE-URL.yaml by the actual provisioner file you want to use and import. More information here.

Get the provisioners definition:

score-k8s provisioners list

Generate the platform specific manifests:

score-k8s generate score.yaml

See the resource outputs:

score-k8s resources list

You can run the following command on each resource listed with the previous command to get their outputs:

score-k8s resources get-outputs

Deploy the generated manifests:

kubectl apply -f manifests.yaml

See the running containers:

kubectl get all