suzuki-shunsuke / issue

MIT License
4 stars 0 forks source link

cue-lang 入門 #75

Open suzuki-shunsuke opened 3 years ago

suzuki-shunsuke commented 3 years ago

Data Validation: https://cuelang.org/docs/usecases/validation/

suzuki-shunsuke commented 2 years ago

cue から YAML を生成

$ cue export --out yaml input.cue
suzuki-shunsuke commented 2 years ago

k8s manifest を cue で抽象化したい

まずは deployment を簡単にラップしたい。

$ kubectl create deploy --dry-run=client -o yaml --image=nginx --replicas=3 app > deployment.yaml

timestamp とかを消す

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: app
  name: app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - image: nginx
        name: nginx

cue に変換する

$ cue import deployment.yaml

deployment.cue が生成される

apiVersion: "apps/v1"
kind:       "Deployment"
metadata: {
    labels: app: "app"
    name: "app"
}
spec: {
    replicas: 3
    selector: matchLabels: app: "app"
    template: {
        metadata: labels: app: "app"
        spec: containers: [{
            image: "nginx"
            name:  "nginx"
        }]
    }
}

cue から yaml を生成する

$ cue export --out yaml deployment.cue

ここから deployment.cue を書き換えていく。

suzuki-shunsuke commented 2 years ago

https://engineering.mercari.com/en/blog/entry/20220127-kubernetes-configuration-management-with-cue/