Hacker News new | past | comments | ask | show | jobs | submit login

I'm working on a project that allows you to put a special "yaml shebang" at the top of any kubernetes manifest. The shebang is actually valid yaml since it's interpreted as a comment. This allows you to combine the declarative kubernetes spec (yaml) with external controller (kubectl)

example my-app.yaml

  #!/usr/local/bin/kubectl -f
  ---
  apiVersion: v1
  kind: Namespace
  metadata:
    name: my-namespace
  ---
  apiVersion: v1
  kind: Pod
  metadata:
    name: my-pod
    namespace: my-namespace
  spec:
    containers:
    - name: nginx
      image: docker.io/nginx:latest
      ports:
      - containerPort: 80
after making my-app.yaml executable you can now invoke the application's config to reconcile itself

  > chmod +x ./my-app.yaml
  
  > ./my-app.yaml apply 
  namespace/my-namespace created
  pod/my-pod created
  
  > ./my-app.yaml get  
  NAME                     STATUS   AGE
  namespace/my-namespace   Active   8s
  
  NAME         READY   STATUS    RESTARTS   AGE
  pod/my-pod   1/1     Running   0          7s
  
  > ./my-app.yaml delete
  namespace "my-namespace" deleted
  pod "my-pod" deleted
obviously this is just a simple example but there is come really cool potential here.



To be fair, this is just how executable scripts work — it’s not a special yaml shebang, just a regular shebang for an executable that happens to take yaml files as it’s input. The underlying OS just invokes the command in the shebang and passes the file as the first parameter, exactly as it would if the shebang were for bash or python.


I never thought I would see the day when someone "discovers" the way shell scripts were intentionally designed 40 years ago. This is why perl and later python uses # for comments.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: