简体   繁体   中英

Writing a startup script to google container engine

I found that startup scripts can be added to Google compute instances using either the console or cli(gcloud). I want to add the startup scripts to google container engine.

The goal is to notify me when the google container engine has changed its state to Running . I though one efficient way is to use startup scripts in container engine, as these scripts will only be executed when the container's status is changed to running.

Any idea how to add startup scripts to container engine or any other way of notifying when the container's status changes to running.

First of all your question is fairly complicated. The concept of startup scripts do not belong to the containers world. As far as I know you can't add startup scripts in Google Container Engine . This is because Container Engine instances are immutable (eg you can't or you are not supposed to modify the operating system, you should just run containers).

If you're trying to run scripts when a container starts/stops you need to forget about startup scripts concept in the Compute Engine world. You can use container lifecycle hooks in Kubernetes (the orchestrator running in Container Engine).

Here's documentation and tutorial about it: https://kubernetes.io/docs/concepts/containers/container-lifecycle-hooks/ https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/

You can approximate the behavior of startup scripts using a DaemonSet with a simple pod that runs in privileged mode. For example code, see https://github.com/kubernetes/contrib/tree/master/startup-script .

Project metadata works for this, here's a terraform example:

resource "google_compute_project_metadata_item" "main" {
    project = abcdefg # this is optional
    key = "startup-script"
    value = "#! /bin/sh\necho hello > /tmp/world"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM