{"id":16552,"date":"2019-06-18T12:00:02","date_gmt":"2019-06-18T03:00:02","guid":{"rendered":"http:\/\/www.skyarch.net\/blog\/?p=16552"},"modified":"2019-10-17T11:11:26","modified_gmt":"2019-10-17T02:11:26","slug":"kubernetes-init-containers%e3%81%a7python%e3%81%ae%e4%bb%ae%e6%83%b3%e7%92%b0%e5%a2%83%e3%82%92%e3%81%a4%e3%81%8f%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86","status":"publish","type":"post","link":"https:\/\/www.skyarch.net\/blog\/kubernetes-init-containers%e3%81%a7python%e3%81%ae%e4%bb%ae%e6%83%b3%e7%92%b0%e5%a2%83%e3%82%92%e3%81%a4%e3%81%8f%e3%81%a3%e3%81%a6%e3%81%bf%e3%82%88%e3%81%86\/","title":{"rendered":"[Kubernetes] init Containers\u3067Python\u306e\u4eee\u60f3\u74b0\u5883\u3092\u3064\u304f\u3063\u3066\u307f\u3088\u3046"},"content":{"rendered":"<p>\u307f\u306a\u3055\u3093\u306f<strong>Kubernetes<\/strong>\u3067Pod\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306b\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306egit clone\u306a\u3069Pod\u306e\u521d\u671f\u5316\u51e6\u7406\u306f\u3069\u306e\u3088\u3046\u306b\u884c\u3063\u3066\u3044\u307e\u3059\u304b\uff1fKubernetes\u306b\u306f<strong>init Containers<\/strong>\u3068\u547c\u3070\u308c\u308b\u521d\u671f\u5316\u5c02\u7528\u306e\u30b3\u30f3\u30c6\u30ca\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u672c\u8a18\u4e8b\u3067\u306f\u3001init Containers\u3092\u5229\u7528\u3057\u3066\u3001Python\u306e\u4eee\u60f3\u74b0\u5883(venv)\u3068\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb(pip install)\u3092\u884c\u3044\u3001Python\u74b0\u5883\u306e\u521d\u671f\u5316\u51e6\u7406\u3092\u884c\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<h2>init Containers\u3068\u306f\uff1f<\/h2>\n<p><a href=\"\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\/init-containers\/%3E)\">init Containers<\/a>\u306fPod\u306e\u521d\u671f\u5316\u51e6\u7406\u3092\u884c\u3046\u305f\u3081\u306b\u3001\u4e00\u5ea6\u3060\u3051\u8d77\u52d5\u3055\u308c\u308bPod\u521d\u671f\u5316\u5c02\u7528\u306e\u30b3\u30f3\u30c6\u30ca\u3067\u3059\u3002Pod\u306b\u306f\u8907\u6570\u306e\u30b3\u30f3\u30c6\u30ca\u3092\u52d5\u304b\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u30b3\u30f3\u30c6\u30ca\u304c\u8d77\u52d5\u3059\u308b\u9806\u756a\u3092\u5236\u5fa1\u3059\u308b\u3053\u3068\u306f\u3067\u304d\u307e\u305b\u3093\u3002init Containers\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30b3\u30f3\u30c6\u30ca\u304c\u8d77\u52d5\u3059\u308b\u524d\u306b\u8d77\u52d5\u3059\u308b\u306e\u3067\u3001Pod\u306e\u521d\u671f\u5316\u51e6\u7406\u3092\u884c\u308f\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002init Containers\u306f\u901a\u5e38\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30f3\u30c6\u30ca\u3068\u540c\u69d8\u306b\u8907\u6570\u306einit Container\u3092\u52d5\u304b\u3059\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30f3\u30c6\u30ca\u3068\u306f\u7570\u306a\u308a\u3001\u8d77\u52d5\u9806\u756a\u304c\u5236\u5fa1\u3055\u308c\u3066\u3044\u3066\u30011\u3064\u306einit Container\u306e\u5b8c\u4e86\u3092\u307e\u3063\u3066\u304b\u3089\u6b21\u306einit Container\u304c\u8d77\u52d5\u3057\u307e\u3059\u3002<\/p>\n<p>init Container\u306e\u9806\u756a\u304c\u5236\u5fa1\u3055\u308c\u3066\u3044\u308b\u306e\u304b\u3001\u78ba\u8a8d\u3092\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002\u78ba\u8a8d\u306e\u305f\u3081\u30012\u3064\u306einit Container\u3092\u542b\u3080Pod\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u521d\u671f\u5316\u51e6\u7406\u3068\u3057\u3066\u5358\u7d14\u306b5\u79d2\u9593sleep\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<pre># file: initcontainers01.yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: test-pod\n  labels:\n    app: test-pod\nspec:\n  initContainers:\n  - name: init1\n    image: alpine:3.9\n    command:\n    - \"sh\"\n    - \"-c\"\n    - \"sleep 5\"\n  - name: init2\n    image: alpine:3.9\n    command:\n    - \"sh\"\n    - \"-c\"\n    - \"sleep 5\"\n  containers:\n  - name: test-pod\n    image: alpine:3.9\n    command:\n    - \"sh\"\n    - \"-c\"\n    - \"touch a.b; tail -f a.b\"\n<\/pre>\n<p><code>kubectl apply<\/code>\u30b3\u30de\u30f3\u30c9\u3067Pod\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre>$ kubectl apply -f initcontainers01.yaml\npod\/test-pod created\n<\/pre>\n<p>\u30b3\u30f3\u30c6\u30ca\u306e\u8d77\u52d5\u9806\u756a\u304c\u5236\u5fa1\u3055\u308c\u3066\u3044\u308b\u304b\u306e\u78ba\u8a8d\u3092\u884c\u3044\u307e\u3059\u3002Pod\u306e\u8a73\u7d30\u60c5\u5831\u3067\u3001\u30b3\u30f3\u30c6\u30ca\u306e\u8d77\u52d5\u65e5\u6642\u3092\u307f\u3066\u307f\u307e\u3059\u3002Pod\u306e\u8a73\u7d30\u60c5\u5831\u3092\u78ba\u8a8d\u3059\u308b\u306b\u306f<code>kubectl describe<\/code>\u30b3\u30de\u30f3\u30c9\u3092\u5229\u7528\u3057\u307e\u3059\u3002\u4ee5\u4e0b\u306e\u5b9f\u884c\u4f8b\u306f\u30b3\u30f3\u30c6\u30ca\u306e\u8d77\u52d5\u65e5\u6642\u306e\u90e8\u5206\u3060\u3051\u3092\u629c\u7c8b\u3057\u305f\u3082\u306e\u3067\u3059\u3002<\/p>\n<pre>$ kubectl describe pods test-pod\n...\u7701\u7565...\nInit Containers:\n  init1:\n...\u7701\u7565...\n      Started:      Tue, 11 Jun 2019 11:05:06 +0900\n      Finished:     Tue, 11 Jun 2019 11:05:11 +0900\n...\u7701\u7565...\n  init2:\n...\u7701\u7565...\n      Started:      Tue, 11 Jun 2019 11:05:13 +0900\n      Finished:     Tue, 11 Jun 2019 11:05:18 +0900\n...\u7701\u7565...\nContainers:\n  test-pod:\n...\u7701\u7565...\n      Started:      Tue, 11 Jun 2019 11:05:19 +0900\n...\u7701\u7565...\n<\/pre>\n<p>\u30b3\u30f3\u30c6\u30ca\u306e\u8d77\u52d5\u65e5\u6642\u3092\u898b\u3066\u307f\u308b\u3068\u3001init1 \u2192 init2 \u2192 test-pod\u306e\u9806\u756a\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u3066\u3001\u30b3\u30f3\u30c6\u30ca\u306e\u8d77\u52d5\u9806\u756a\u306f\u5b88\u3089\u308c\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002init Containers\u3067\u3042\u308binit1\u3068init2\u304c\u5e73\u884c\u306b\u8d77\u52d5\u3055\u308c\u3066\u3044\u306a\u304f\u3001init1\u306e\u5b8c\u4e86\u3092\u5f85\u3063\u3066init2\u304c\u8d77\u52d5\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30f3\u30c6\u30ca\u3067\u3042\u308btest-pod\u306f\u3001\u3059\u3079\u3066\u306einit Container\u304c\u5b8c\u4e86\u3057\u305f\u3042\u3068\u306b\u8d77\u52d5\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u78ba\u8a8d\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<h2>containers.lifecycle.postStart\u3068\u306e\u9055\u3044\u306f\uff1f<\/h2>\n<p>\u30b3\u30f3\u30c6\u30ca\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u30d5\u30c3\u30af\u306b<strong>postStart<\/strong>\u304c\u3042\u308a\u307e\u3059\u3002postStart\u306f\u30b3\u30f3\u30c6\u30ca\u304c\u4f5c\u6210\u3055\u308c\u305f\u76f4\u5f8c\u306b\u4f55\u304b\u3057\u3089\u306e\u51e6\u7406\u3092\u5b9f\u884c\u3055\u305b\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u305f\u3060\u3057\u3001<strong>\"\u30b3\u30f3\u30c6\u30ca\u304c\u4f5c\u6210\u3055\u308c\u305f\u76f4\u5f8c\"<\/strong>\u306e\u305f\u3081\u3001\u30b3\u30f3\u30c6\u30ca\u306e<strong>ENTRYPOINT<\/strong>\u306e\u5b9f\u884c\u524d\u306bpostStart\u304c\u5b9f\u884c\u3055\u308c\u308b\u4fdd\u8a3c\u306f\u3042\u308a\u307e\u305b\u3093\u3002\u3064\u307e\u308a\u3001ENTRYPOINT\u5b9f\u884c\u524d\u306b\u521d\u671f\u5316\u51e6\u7406\u3092\u3059\u308b\u76ee\u7684\u3067postStart\u3092\u5b9f\u884c\u3059\u308b\u306b\u306f\u3001ENTRYPOPINT\u304c\u5b9f\u884c\u3055\u308c\u305f\u304b\u306e\u78ba\u8a8d\u3092postStart\u306e\u30b3\u30de\u30f3\u30c9\u5185\u3067\u5b9f\u88c5\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3053\u308c\u306b\u5bfe\u3057\u3066init Containers\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30f3\u30c6\u30ca\u306e\u8d77\u52d5\u524d\u306b\u5b9f\u884c\u3055\u308c\u308b\u306e\u3067\u3001\u78ba\u5b9f\u306b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30f3\u30c6\u30ca\u306eENTRYPOINT\u5b9f\u884c\u524d\u306b\u521d\u671f\u5316\u51e6\u7406\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<h2>Python\u306e\u4eee\u60f3\u74b0\u5883\u3092init Container\u3067\u4f5c\u3063\u3066\u307f\u308b<\/h2>\n<h3>\u691c\u8a3c\u69cb\u6210<\/h3>\n<p>\u691c\u8a3c\u306b\u306fDocker Desktop for Windows\u306eKubernetes\u74b0\u5883\u3092\u5229\u7528\u3057\u307e\u3057\u305f\u3002<\/p>\n<pre>$ kubectl version --short\nClient Version: v1.14.1\nServer Version: v1.10.11\n$ kubectl config get-clusters\nNAME\ndocker-for-desktop-cluster\n<\/pre>\n<p>Python\u3092\u52d5\u4f5c\u3055\u305b\u308b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b5\u30fc\u30d0\u306b\u306f<strong>Nginx Unit<\/strong>\u3092\u5229\u7528\u3057\u307e\u3057\u305f\u3002<a href=\"https:\/\/www.nginx.com\/products\/nginx-unit\/\">https:\/\/www.nginx.com\/products\/nginx-unit\/<\/a><\/p>\n<h3>\u521d\u671f\u5316\u51e6\u7406\u306e\u6d41\u308c<\/h3>\n<p>\u4ee5\u4e0b\u306e\u521d\u671f\u5316\u51e6\u7406\u3092\u884c\u3046Pod\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><strong>init Conteiners<\/strong><\/p>\n<ol>\n<li>GitHub\u304b\u3089\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092clone\u3059\u308b\u3002<\/li>\n<li>Python\u306e\u4eee\u60f3\u74b0\u5883(venv)\u3092\u4f5c\u6210\u3059\u308b\u3002<\/li>\n<li>Python\u306e\u4eee\u60f3\u74b0\u5883\u3092\u6709\u52b9\u306b\u3059\u308b\u3002<\/li>\n<li>pip\u3067Python\u306e\u30e2\u30b8\u30e5\u30fc\u30eb(Flask)\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/li>\n<\/ol>\n<p><strong>containers.lifecycle.postStart<\/strong><\/p>\n<ol>\n<li>curl\u3067Nginx Unit\u306e\u8a2d\u5b9a\u3092\u53cd\u6620\u3059\u308b\u3002<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>init Container\u3068\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30f3\u30c6\u30ca\u3067\u540c\u3058EmptyDir\u306e\u30dc\u30ea\u30e5\u30fc\u30e0\u3092\u30de\u30a6\u30f3\u30c8\u3059\u308b\u3053\u3068\u3067\u3001init Container\u3067\u521d\u671f\u5316\u3057\u305f\u74b0\u5883\u3068\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30f3\u30c6\u30ca\u3067\u3082\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p style=\"text-align: center\"><a href=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/06\/initContainers.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-16556\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/06\/initContainers.png\" alt=\"\" width=\"420\" height=\"332\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/06\/initContainers.png 420w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/06\/initContainers-300x237.png 300w\" sizes=\"auto, (max-width: 420px) 100vw, 420px\" \/><\/a><\/p>\n<h3>ConfigMap\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n<p>Nginx Unit\u306e\u8a2d\u5b9a\u306f<strong>ConfigMap<\/strong>\u3067\u5b9a\u7fa9\u3057\u3066\u3044\u307e\u3059\u3002Python\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306f\"path\"\u306b\u6307\u5b9a\u3057\u305f\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u914d\u7f6e\u3057\u307e\u3059\u3002\u4eca\u56de\u306e\u691c\u8a3c\u3067\u306f\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u914d\u5e03\u3092Pod\u306einitContainers\u306egit clone\u30b3\u30de\u30f3\u30c9\u3067\u884c\u3044\u307e\u3059\u3002\u307e\u305f\u3001Python\u4eee\u60f3\u74b0\u5883\u306e\u30d1\u30b9\u3092\"home\"\u306b\u8a2d\u5b9a\u3057\u307e\u3059\u304c\u3001Python\u306e\u4eee\u60f3\u74b0\u5883\u3082Pod\u306einitContainers\u306e\u30b3\u30de\u30f3\u30c9\u3067\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre>#file:nginx-unit-configmap.yaml\napiVersion: v1\nkind: ConfigMap\nmetadata:\n  name: nginx-unit-json\ndata:\n  unit.conf.json: |-\n    {\n      \"listeners\": {\n        \"*:8300\": {\n          \"pass\": \"applications\/flask\"\n        }\n      },  \n      \"applications\": {\n        \"flask\": {\n          \"type\": \"python 3.5\",\n          \"processes\": 1,\n          \"working_directory\": \"\/app\/python\",\n          \"path\": \"\/app\/python\/flask\",\n          \"home\": \"\/app\/python\/venv\",\n          \"module\": \"index\",\n          \"user\": \"root\",\n          \"group\": \"root\",\n        }\n      },\n    }\n<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u305f\u3089\u3001<code>kubectl apply<\/code>\u30b3\u30de\u30f3\u30c9\u3067ConfigMap\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre>$ kubectl apply -f nginx-unit-configmap.yaml\nconfigmap\/nginx-unit-json created\n<\/pre>\n<h3>Pod\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n<p>Pod\u306e\u5b9a\u7fa9\u3092\u884c\u3044\u307e\u3059\u3002Pod\u306b\u306f\u521d\u671f\u5316\u7528\u306einit Container\u3068\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u7528\u306e\u30b3\u30f3\u30c6\u30ca\u304c\u542b\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre># file: nginx-unit.yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: nginx-unit\n  labels:\n    app: nginx-unit\nspec:\n  initContainers:\n    - name: init-client\n      image: python:3.5-alpine\n      command:\n        - \"\/bin\/sh\"\n        - \"-c\"\n        - \"apk add git; \\\n           git clone https:\/\/github.com\/easydoggie\/testapp.git \/tmp\/git; \\\n           python -m venv \/tmp\/git\/python\/venv; \\\n           . \/tmp\/git\/python\/venv\/bin\/activate; \\\n           pip install Flask\"\n      volumeMounts:\n        - name: nginx-unit-storage\n          mountPath: \/tmp\/git\n  containers:\n    - name: nginx-unit\n      image: nginx\/unit:1.9.0-python3.5\n      lifecycle:\n        postStart:\n            exec: \n                command:\n                    - sh\n                    - -c\n                    - \"while [ ! -e \/var\/run\/control.unit.sock ]; do sleep 1; done  \\\n                       &amp;&amp; curl -X PUT --data-binary @\/tmp\/unit.conf.json --unix-socket \/var\/run\/control.unit.sock http:\/\/localhost\/config\"\n      ports:\n      - name: http\n        containerPort: 8300\n        protocol: TCP\n      volumeMounts:\n        - name: nginx-unit-storage\n          mountPath: \/app\/python\n          subPath: python\n        - name: nginx-unit-config\n          mountPath: \/tmp\n  volumes:\n    - name: nginx-unit-storage\n      emptyDir: {}\n    - name: nginx-unit-config\n      configMap:\n        name: nginx-unit-json\n<\/pre>\n<p>init Container\u3067\u5229\u7528\u3057\u305fpython\u306e\u30d9\u30fc\u30b9\u30a4\u30e1\u30fc\u30b8\u306b\u306fEntrypoint\u306f\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u307e\u305b\u3093\u3002Entrypoint\u304c\u8a2d\u5b9a\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3067\u3001initContainers.command\u306bPod\u306e\u521d\u671f\u5316\u51e6\u7406\u3092\u8a18\u8ff0\u3057\u3066\u3044\u304d\u307e\u3059\u3002Git\u306e\u30af\u30ed\u30fc\u30f3\u5143\u3084\u5fc5\u8981\u306aPython\u30d1\u30c3\u30b1\u30fc\u30b8\u306f\u3001\u5229\u7528\u3059\u308b\u74b0\u5883\u306b\u5408\u308f\u305b\u3066\u4fee\u6b63\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u521d\u671f\u5316\u51e6\u7406\u306e\u6982\u8981\u306f\u3001\u4ee5\u4e0b\u306e\u30b3\u30e1\u30f3\u30c8\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre>- \"apk add git; \\\\ #\u30d9\u30fc\u30b9\u30a4\u30e1\u30fc\u30b8\u306bGit\u304c\u306a\u3044\u306e\u3067Git\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\n   git clone https:\/\/github.com\/easydoggie\/testapp.git \/tmp\/git; \\ #\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092git clone\n   python -m venv \/tmp\/git\/python\/venv; \\ #Python\u306e\u4eee\u60f3\u74b0\u5883\u3092\u4f5c\u6210\n   . \/tmp\/git\/python\/venv\/bin\/activate; \\ #Python\u306e\u4eee\u60f3\u74b0\u5883\u3092\u6709\u52b9\u5316\n   pip install Flask\" #Python\u306e\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\n<\/pre>\n<p>init Container\u3067\u306e\u521d\u671f\u5316\u304c\u5b8c\u4e86\u3057\u305f\u5f8c\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306e\u30b3\u30f3\u30c6\u30ca\u304c\u8d77\u52d5\u3057\u307e\u3059\u3002\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30b3\u30f3\u30c6\u30ca\u304c\u8d77\u52d5\u3059\u308b\u30bf\u30a4\u30df\u30f3\u30b0\u3067\u3001lifecycle.postStart\u3067Nginx Unit\u306e\u8a2d\u5b9a\u3092\u53cd\u6620\u3055\u305b\u3066\u3044\u307e\u3059\u3002postStart\u306f\u30b3\u30f3\u30c6\u30ca\u306eEntrypoint(\u30d7\u30ed\u30bb\u30b9\u5b9f\u884c)\u306e\u524d\u306b\u5b9f\u884c\u3055\u308c\u308b\u4fdd\u8a3c\u304c\u306a\u3044\u305f\u3081\u3001postStart\u5185\u3067Nginx Unit\u306e\u8d77\u52d5\u3092while\u30eb\u30fc\u30d7\u3067\u78ba\u8a8d\u3057\u3066\u3044\u307e\u3059\u3002Nginx Unit\u306e\u8d77\u52d5\u3092\u78ba\u8a8d\u3057\u305f\u5f8c\u306b\u3001curl\u30b3\u30de\u30f3\u30c9\u3067Nginx Unit\u3078\u8a2d\u5b9a\u3092\u53cd\u6620\u3055\u305b\u307e\u3059\u3002<\/p>\n<pre>lifecycle:\n  postStart:\n    exec: \n      command:\n        - sh\n        - -c\n        - \"while [ ! -e \/var\/run\/control.unit.sock ]; do sleep 1; done  \\ #Nginx Unit\u306e\u8d77\u52d5\u78ba\u8a8d\n           &amp;&amp; curl -X PUT --data-binary @\/tmp\/unit.conf.json --unix-socket \/var\/run\/control.unit.sock &lt;http:\/\/localhost\/config&gt;\"\n<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u305f\u3089\u3001<code>kubectl apply<\/code>\u30b3\u30de\u30f3\u30c9\u3067Pod\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre>$ kubectl apply -f nginx-unit-pod.yaml\npod\/nginx-unit created\n<\/pre>\n<p>init Containers\u306b\u3088\u308bPod\u306e\u521d\u671f\u5316\u51e6\u7406\u304c\u6700\u521d\u306b\u5b9f\u884c\u3055\u308c\u308b\u305f\u3081\u3001Pod\u306e\u8d77\u52d5\u307e\u3067\u306b\u591a\u5c11\u306e\u6642\u9593\u304c\u304b\u304b\u308a\u307e\u3059\u3002<code>kubectl get pods<\/code>\u30b3\u30de\u30f3\u30c9\u306eSTATUS\u304cInit\u306e\u6642\u306f\u3001\u521d\u671f\u5316\u51e6\u7406\u306e\u5b9f\u65bd\u4e2d\u3067\u3059\u3002STATUS\u304cRunning\u306b\u306a\u308c\u3070\u3001Pod\u306e\u8d77\u52d5\u304c\u5b8c\u4e86\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>$ kubectl get pods\nNAME         READY   STATUS     RESTARTS   AGE\nnginx-unit   0\/1     Init:0\/1   0          15s\n$ kubectl get pods\nNAME         READY   STATUS    RESTARTS   AGE\nnginx-unit   1\/1     Running   0          19s\n<\/pre>\n<h3>Service\u3092\u4f5c\u6210\u3059\u308b<\/h3>\n<p>\u30a2\u30af\u30bb\u30b9\u78ba\u8a8d\u3092\u3059\u308b\u305f\u3081\u306eService\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002\u4eca\u56de\u306e\u691c\u8a3c\u3067\u306fNodePort\u3092\u5229\u7528\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>apiVersion: v1\nkind: Service\nmetadata:\n  name: testservice\nspec:\n  type: NodePort\n  ports:\n  - protocol: TCP\n    port: 8300\n    targetPort: 8300\n    nodePort: 30080\n  selector:\n    app: nginx-unit\n<\/pre>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u305f\u3089\u3001<code>kubectl apply<\/code>\u30b3\u30de\u30f3\u30c9\u3067Service\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre>$ kubectl apply -f nginx-unit-service.yaml\nservice\/testservice created\n<\/pre>\n<h3>\u52d5\u4f5c\u78ba\u8a8d<\/h3>\n<p>http:\/\/localhost:30080\u306b\u30a2\u30af\u30bb\u30b9\u3057\u3066\u3001\u52d5\u4f5c\u78ba\u8a8d\u3092\u3057\u3066\u307f\u307e\u3059\u3002\u753b\u9762\u306b'Hello, World!'\u3068\u8868\u793a\u3055\u308c\u308c\u3070\u3001init Containers\u306e\u521d\u671f\u5316\u51e6\u7406\u3067\u4f5c\u6210\u3057\u305fPython\u306e\u4eee\u60f3\u74b0\u5883\u4e0a\u306eFlask\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u304c\u6b63\u5e38\u306b\u52d5\u4f5c\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>$ curl http:\/\/localhost:30080\nHello, World!\n<\/pre>\n<h2>Helm Chart<\/h2>\n<p>\u672c\u8a18\u4e8b\u3067\u306fPython\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u76f4\u63a5kubectl\u30b3\u30de\u30f3\u30c9\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002\u5225\u306e\u65b9\u6cd5\u3068\u3057\u3066<strong>Helm<\/strong>\u3092\u5229\u7528\u3057\u3066Kubernetes\u306b\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5\u3082\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>GitHub\u4e0a\u306bNginx Unit + PHP\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3(Adminer)\u3092\u3001\u672c\u8a18\u4e8b\u3068\u540c\u69d8\u306binit Container\u3067\u521d\u671f\u5316\u3059\u308bHelm Chart\u3092\u516c\u958b\u3057\u3066\u3044\u307e\u3059\u3002Helm Chart\u3092\u4f7f\u3063\u3066init Container\u3092\u5b9f\u88c5\u3059\u308b\u969b\u306e\u53c2\u8003\u306b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/easydoggie\/EasyDoggie\/tree\/master\/adminer\/adminer\">https:\/\/github.com\/easydoggie\/EasyDoggie\/tree\/master\/adminer\/adminer<\/a><\/p>\n<p>Helm\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u65b9\u6cd5\u306f\u3001<a href=\"http:\/\/www.skyarch.net\/blog\/?p=16350\">\u5225\u8a18\u4e8b<\/a>\u3092\u53c2\u7167\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<h2>\u3055\u3044\u3054\u306b<\/h2>\n<p>KUbernetes\u306e\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u521d\u671f\u5316\u51e6\u7406\u306e\u4e00\u3064\u306e\u65b9\u6cd5\u3068\u3057\u3066\u3001init Containers\u3068postStart\u306e\u5229\u7528\u4f8b\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002postStart\u306f\u51e6\u7406\u304c\u5b9f\u884c\u3055\u308c\u308b\u30bf\u30a4\u30df\u30f3\u30b0\u304c\u30b3\u30f3\u30c6\u30ca\u4f5c\u6210\u76f4\u5f8c\u3067\u3001Entrypoint\u306e\u524d\u306b\u5b9f\u884c\u3055\u308c\u308b\u4fdd\u8a3c\u304c\u306a\u3044\u3053\u3068\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3067\u3059\u3002Pod\u306e\u521d\u671f\u5316\u51e6\u7406\u306f\u3001\u78ba\u5b9f\u306b\u8d77\u52d5\u9806\u756a\u304c\u5236\u5fa1\u3067\u304d\u308binit Containers\u3067\u5b9f\u88c5\u3067\u304d\u308c\u3070\u78ba\u5b9f\u3067\u3059\u3002\u30b3\u30f3\u30c6\u30ca\u306e\u30e9\u30a4\u30d5\u30b5\u30a4\u30af\u30eb\u3084\u5b9f\u884c\u9806\u756a\u306e\u4fdd\u8a3c\u306a\u3069\u3092\u610f\u8b58\u3057\u3066\u3001\u5b89\u5168\u304b\u3064\u5b89\u5fc3\u3057\u3066\u904b\u7528\u3067\u304d\u308b\u30b3\u30f3\u30c6\u30ca\u3092\u4f5c\u3063\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<div id=\"attachment_17346\" style=\"width: 508px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.skyfantasylab.work\/\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-17346\" class=\"size-full wp-image-17346\" src=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/09\/SFL-logo-white-512.png\" alt=\"\u30b9\u30ab\u30a4\u30a2\u30fc\u30c1 \u30d5\u30a1\u30f3\u30bf\u30b8\u30fc\u7814\u7a76\u5ba4\" width=\"498\" height=\"498\" srcset=\"https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/09\/SFL-logo-white-512.png 498w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/09\/SFL-logo-white-512-150x150.png 150w, https:\/\/www.skyarch.net\/blog\/wp-content\/uploads\/2019\/09\/SFL-logo-white-512-300x300.png 300w\" sizes=\"auto, (max-width: 498px) 100vw, 498px\" \/><\/a><p id=\"caption-attachment-17346\" class=\"wp-caption-text\">\u30b9\u30ab\u30a4\u30a2\u30fc\u30c1 \u30d5\u30a1\u30f3\u30bf\u30b8\u30fc\u7814\u7a76\u5ba4<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u307f\u306a\u3055\u3093\u306fKubernetes\u3067Pod\u3092\u4f5c\u6210\u3059\u308b\u3068\u304d\u306b\u3001\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u306egit clone\u306a\u3069Pod\u306e\u521d\u671f\u5316\u51e6\u7406\u306f\u3069\u306e\u3088\u3046\u306b\u884c\u3063\u3066\u3044\u307e\u3059\u304b\uff1fKubernetes\u306b\u306finit Containers\u3068\u547c\u3070\u308c\u308b\u521d\u671f\u5316\u5c02\u7528\u306e\u30b3&#8230;<\/p>\n","protected":false},"author":1,"featured_media":16382,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"16552","footnotes":""},"categories":[83],"tags":[94,521,394],"class_list":{"0":"post-16552","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-devops","8":"tag-docker","9":"tag-helm","10":"tag-kubernetes","11":"ja"},"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/16552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/comments?post=16552"}],"version-history":[{"count":7,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/16552\/revisions"}],"predecessor-version":[{"id":17369,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/posts\/16552\/revisions\/17369"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media\/16382"}],"wp:attachment":[{"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/media?parent=16552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/categories?post=16552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.skyarch.net\/blog\/wp-json\/wp\/v2\/tags?post=16552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}