2016-03-21 12 views
0

私は、/ pgを起動したときに実行するGoogleコンテナに/usr/startup.shスクリプトを作成しました。Googleコンテナの起動スクリプト

以下のようにyamlのコマンドでやってみました。

コマンド: "SH /usr/start.sh" コマンド:[ "SH"、 "-c"、 "/usr/start.sh"]のいずれかの種類がある場合

せて頂きますGoogleコンテナ/ポッドの起動時に定義されたスクリプトを実行することができます。

答えて

2

poststart lifecycle hookをご覧ください。

例がkubernetes repoで見つけることができます:

containers: 
    - name: nginx 
    image: resouer/myapp:v6 
    lifecycle: 
     postStart: 
     exec: 
      command: 
      - "cp" 
      - "/app/myapp.war /work" 
ここ

は次のとおりです。

// 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"` 
} 
+0

ReplicationControllerで機能していないようです。それはポッドで動作します。 Podは "RunContainerError"ステータスになります。 V1 種類::ReplicationController メタデータ: 名前空間:デフォルト 名:testtomcat スペック: レプリカ:2 セレクタ: アプリ:testtomcat テンプレート: メタデータ: 私が何か apiVersionをしないのです場合は私に知らせてくださいラベル: アプリ:testtomcat スペック: コンテナ: - 名前:testtomcat 画像:gcr.io/project/tomcat-:v4 ライフサイクル: postStart: 幹部: コマンド: - "/usr/start.sh" ports: - containerPort:8080 – Nitin

+0

これで、以下のように試してみました。 ライフサイクル: postStart: EXEC: コマンド: - "SH" - "/usr/local/s3fsmount.sh" の助けを ありがとう! – Nitin

0

ないすべてのポッドのためのノードの起動時に実行する起動スクリプト、。ノード上でポッドが開始されるたびにkubeletに「フック」を実行することは現在ありません。おそらくあなたがしようとしていることを説明できますか?

+0

種類:yamlのReplicationController GoogleストレージをPodにマウントしようとしています。 Docker Imageに必要なパッケージをインストールし、Google Container Engineでテストしました。手動でのマウントはうまくいきますが、自動化できません。 yamlファイルのコマンドパラメータでシェルスクリプトを使用しようとしました。/etc/fstabに "my-bucket/mount/point gcsfuse rw、auto、user"を追加しようとしましたが、動作しません。ポッドで毎回 "mount/mount/point"コマンドを実行する必要があります。ポッドの起動時に "gcsfuse --implicit-dirs my-bucket/mount/point"または "mount/mount/point"コマンドを実行したいと考えています – Nitin

+0

今度はうまくやってみましょう ライフサイクル: postStart: EXEC: コマンド: - "SH" - "/usr/local/s3fsmount.sh" の助けを ありがとう! – Nitin

関連する問題