谷歌容器启动脚本

时间:2016-03-21 10:37:56

标签: kubernetes google-kubernetes-engine

我在google容器中创建了/usr/startup.sh脚本,希望在每个pod的启动时执行它。

我尝试通过yaml中的命令来执行此操作。

命令:" sh /usr/start.sh" 命令:[" sh"," -c"," /usr/start.sh"]

如果有任何方式可以在google容器/ pod中启动时执行已定义的脚本,请告诉我。

2 个答案:

答案 0 :(得分:2)

您可能需要查看postStart lifecycle hook

可以在kubernetes repo

中找到一个示例
  containers:
  - name: nginx
    image: resouer/myapp:v6
    lifecycle:
      postStart:
        exec:
          command:
            - "cp"
            - "/app/myapp.war /work"

以下是API docs

// Lifecycle describes actions that the management system should take in response to container lifecycle
// events.  For the PostStart and PreStop lifecycle handlers, management of the container blocks
// until the action is complete, unless the container process fails, in which case the handler is aborted.
type Lifecycle struct {
    // PostStart is called immediately after a container is created.  If the handler fails, the container
    // is terminated and restarted.
    PostStart *Handler `json:"postStart,omitempty"`
    // PreStop is called immediately before a container is terminated.  The reason for termination is
    // passed to the handler.  Regardless of the outcome of the handler, the container is eventually terminated.
    PreStop *Handler `json:"preStop,omitempty"`
}

答案 1 :(得分:0)

启动脚本在节点启动时运行,而不是在每个pod上运行。当pod在节点上启动时,我们目前在kubelet中没有“钩子”来运行。你能解释一下你想做什么吗?