google 容器启动脚本

google container startup script

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

我尝试通过 yaml 中的命令来完成它,如下所示。

命令:"sh /usr/start.sh" 命令:["sh"、“-c”、“/usr/start.sh”]

如果有任何一种方法可以在 google container/pod 启动时执行定义的脚本,请告诉我。

您可能需要查看 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"`
}

节点启动时的启动脚本运行,并非针对每个 pod。每当 pod 在节点上启动时,我们目前在 kubelet 中没有 "hook" 到 运行。你能解释一下你想做什么吗?