Using Kubernetes' hooks

1/26/2015

I would like to try Kubernetes' hooks but I didn't find any example how I should do it. As far as I know, with this hooks I can run bash scripts in freshly created containers and prior to terminate them.

I've found just a short documentation which say this is possible but that's all.

Do somebody have an example or something useful info?

Thanks in advance.

-- Halacs
kubernetes

2 Answers

1/30/2015

With the above answer I could try postStart hook, and I found a bug which was solved at the end of the last year but not published it yet in Fedora's testing repository just in rawhide repo.

The repos should be updated in the next couple of days.

Further details: https://github.com/kubernetes/kubernetes/issues/3930

-- Halacs
Source: StackOverflow

1/27/2015

I don't see any examples .yaml files, but Kubernetes API v1 describes the lifecycle events in the same manner. Currently, only PostStart and PreStop are defined and you should be able to use them by adding a lifecycle section to a container in your pod definition.

Based on reading the API definition, something like this should work (disclaimer: I haven't actually tried it myself):

containers:
  - name: lifecycle
    image: busybox
    lifecycle:
      postStart:
        exec:
          command:
            - "touch"
            - "/var/log/lifecycle/post-start"
      preStop:
        httpGet:
          path: "/abort"
          port: 8080
-- Robert Bailey
Source: StackOverflow