Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.44 KB

README.adoc

File metadata and controls

51 lines (38 loc) · 1.44 KB

Basic Pkl/K8s Example

This example demonstrates how to

  • convert YAML manifests to Pkl

  • evaluate Pkl manifests to YAML

  • catch manifest errors during evaluation

  • apply Pkl manifests to Kubernetes.

To convert the YAML manifests located in the yaml directory to Pkl, run io.k8s.convert for each YAML file:

$ pkl eval -p input=../../yaml/frontend.yaml \
    -o frontend.pkl \
    package://pkg.pkl-lang.org/pkl-pantry/k8s.contrib@1.0.1#/convert.pkl

$ pkl eval -p input=../../yaml/redis-primary.yaml \
    -o redis-primary.pkl \
    package://pkg.pkl-lang.org/pkl-pantry/k8s.contrib@1.0.1#/convert.pkl

$ pkl eval -p input=../../yaml/redis-secondary.yaml \
    -o redis-secondary.pkl \
    package://pkg.pkl-lang.org/pkl-pantry/k8s.contrib@1.0.1#/convert.pkl

To evaluate the Pkl manifests back to YAML, run:

$ pkl eval *.pkl

To see Pkl validation in action, open frontend.pkl, make one of the following edits, and re-run pkl eval *.pkl:

  • pork = 80 in line 18 (misspelled field name)

  • port = "80" in line 18 (wrong type of value)

  • port = 99999 in line 18 (value out of range)

  • type = "Custom" in line 15 (invalid enum value)

To apply the Pkl manifests to Kubernetes, run:

$ pkl eval *.pkl | kubectl apply -f -