tl;dr
- GKEã§k8sï¼kubernetesï¼ã¯ã©ã¹ã¿ãä½æããã¨ãåãã¼ãã¯GCEã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦èµ·åãã
- GCEã¤ã³ã¹ã¿ã³ã¹ã«ã¯ preemptible ã¢ã¼ããæå®ã§ããããã¯GKEã¯ã©ã¹ã¿ã¨ãã¦èµ·åãããã¼ãã«å¯¾ãã¦ãæå®å¯è½
- GCEã®f1-microç¡ææ ã®é©ç¨ã¨åããã¦ããã®éç¨è²»ç¨ã¯ç´ $7.68/month
åæ©
GKEã¯ã©ã¹ã¿ãç¶æããæå®æéã¦ãããã ãã¼
— a-know | Daisuke Inoue (@a_know) 2018å¹´6æ11æ¥
趣å³éçºç¨éã¨ãã¦æ軽ã«ãããã試ããã¨ãã§ãã¦ãããã§ãã¦ã§ããã ãå®ããããã³ã³ãããªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ç°å¢ï¼k8sç°å¢ï¼ãã»ããã
- k8sãã®ãã®ãéç¨ãããã»ãã®ãã¦ãã¦ãå¦ã³ããã¨ããããã§ã¯ãªãã®ã§ããã¼ã¸ããµã¼ãã¹ããã
- ãk8sä¸ã§ã¢ããªã±ã¼ã·ã§ã³ã»ãµã¼ãã¹ãéç¨ããçµé¨ããããã
- ãã®ä¸ã§ãã§ããã ãå®ãéç¨ããã
GKEã§k8sï¼kubernetesï¼ã¯ã©ã¹ã¿ãèµ·åããã¨ãåãã¼ãã¯GCEã¤ã³ã¹ã¿ã³ã¹ã¨ãã¦èµ·åãããããã¦GCEã¤ã³ã¹ã¿ã³ã¹ã«ã¯ preemptible ã¢ã¼ãã¨ãããé常ã®ä¾¡æ ¼ã®æ°åã®ä¸ã®ä¾¡æ ¼ã§ä½¿ããåé¢ã以ä¸ã®ãããªå¶ç´ã課ãããããã¨ã¦ãåæ§çãªç¹å¾´ãæã¤ã¤ã³ã¹ã¿ã³ã¹ãä½æãããã¨ãã§ããã
- ãã¤ã·ã£ãããã¦ã³ããããããããªã
- æ大ã§ã24æéããèµ·åãã¤ã¥ããããªã
- è¦æ±ããã¿ã¤ãã³ã°ã§ã¤ã³ã¹ã¿ã³ã¹ãç«ã¡ä¸ãããã¨ãã§ããªãå¯è½æ§ããã
ãã® preemptible ãªãã·ã§ã³ã¯GKEã¯ã©ã¹ã¿ãä½æããã¨ãã§ãæå®ãããã¨ãã§ããããã¦GKEã使ããã¨ã§ãã® preemptible ã¤ã³ã¹ã¿ã³ã¹ã®ãã¡ãªãããæå°åãã¤ã¤ãæ´»ç¨ã§ãããã ã£ãã®ã§ãä»åã¯ããã試ãã¦ã¿ãã
ãã¼ãã« preemptible ã¤ã³ã¹ã¿ã³ã¹ã使ã£ãGKEã¯ã©ã¹ã¿ã®ç«ã¡ä¸ãæé
ã¾ãã¯ä¸æºåãGKEãã¯ããã¨ããGCPã«å¯¾ãã¦ã®æä½ã¯ gcloud
ã³ãã³ãããk8sã¯ã©ã¹ã¿ã«å¯¾ããæä½ã«ã¯ kubectl
ã³ãã³ããããããã便å©ãªã®ã§ãã¾ã ã®äººã¯ã»ããã¢ãããã¾ãããã
- GCloud SDKã®ã»ããã¢ããããã
- https://cloud.google.com/sdk/downloads?hl=ja ãã SDK ã DL
gcloud init
ã³ãã³ãã§è¨å®ãé²ãã
- kubectl ã®ã»ããã¢ãã
gcloud components update
gcloud components update kubectl
ãªã¼ã¸ã§ã³é¸æã®éãGCEã®f1-microç¡ææ ãæ´»ç¨ããããããªã¼ã¸ã§ã³ã åãã¼ã¸ãã¢ãé¤ãç±³å½ãªã¼ã¸ã§ã³
ã®ãããããæå®ããï¼ãªã¼ã¸ã§ã³ä¸è¦§ ï¼ã
ããã¾ã§ã§ãããããã£ããGKEã¯ã©ã¹ã¿ãèµ·åãã¦ã¿ãã以ä¸ã®ã³ãã³ãããããã
gcloud container clusters create <ã¯ã©ã¹ã¿å> --preemptible --machine-type=f1-micro --num-nodes=3 --disk-size=10
ã¯ã©ã¹ã¿ãç«ã¡ä¸ããéãã¯ã©ã¹ã¿ãæ§æãã GCE ã¤ã³ã¹ã¿ã³ã¹ã® machine-type ãæå®ã§ããã®ã ãã©ããã®ã¹ããã¯ã«ãããæå°éæ±ããããã¤ã³ã¹ã¿ã³ã¹æ°ãç°ãªããf1-micro ã®å ´åã¯ã3ã¤ã³ã¹ã¿ã³ã¹ï¼--num-nodes=2
ãªã©ã¨æå®ãã¦ãã¨ã©ã¼ã¨ãªãï¼ãä¸è¨ã®ã³ãã³ãã§3ã¤ã® preemptible ãªã¤ã³ã¹ã¿ã³ã¹ã§æ§æãããk8sã¯ã©ã¹ã¿ãä½æãããã
ï¼2018-06-21 追è¨ï¼ãã¡ãã®ããã°ã§è©¦ãã¦ããã ããçµæã--enable-autorepair
ãªãã·ã§ã³ã®æå®ããªãã¨è¦åãã§ããããã§ããgcloud
ã®ãã¼ã¸ã§ã³ã®éãããªãè£è¶³ãããã¨ããããã¾ãï¼
ä¸è¨ã®ããã«ãã¦ä½ãããã¯ã©ã¹ã¿ã§ã¯ãpreemptible ã¨ãã¦ãããã¨ã§ä»®ã«ä¸æã«ã·ã£ãããã¦ã³ãããã¤ã³ã¹ã¿ã³ã¹ããã£ã¦ããããã«3ã¤ã®ã¤ã³ã¹ã¿ã³ã¹ãä¿ã¤ãããpreemptible ãªã¤ã³ã¹ã¿ã³ã¹ãä½ãããã
ãã¨ãã£ã¦ãpreemptible ãªã¤ã³ã¹ã¿ã³ã¹ã®ã¿ã§ k8s ã¯ã©ã¹ã¿ãæ§æãã¦ãã¾ãã¨ãææªããã¹ã¦ãåæã«ããªããªã£ãã®ã¡ãã²ã¨ã¤ãã¤ã³ã¹ã¿ã³ã¹ã確ä¿ã§ããªããã¨ããäºæ ã«é¥ãå¯è½æ§ãããã®ã§ãä¸è¨ã¨ã¯å¥ã«f1-microã¤ã³ã¹ã¿ã³ã¹1å°ã¯æä½éãèµ·åãã¦ããã¦ããããã¨ã«ãããããã§ãã®ã³ã¹ããå¿é ã«ãªããããããªããã©ãGCPã§ã¯ f1-micro ã¤ã³ã¹ã¿ã³ã¹1å°ã¯ãã£ã¨ç¡æï¼Google Cloud Free Tier | Google Cloud Platform Free Tierï¼ãªã®ã§ãããã«ãããé©ç¨ããããããºã
以ä¸ã®ã³ãã³ãã§ãããã»ã©ä½æãã preemptible ãªã¯ã©ã¹ã¿ã«å¯¾ã㦠preemptible ã§ãªã f1-micro ã¤ã³ã¹ã¿ã³ã¹1å°ã ãã®ãã¼ããã¼ã«ã追å ããã
gcloud container node-pools create <ãã¼ããã¼ã«å> --cluster <ã¯ã©ã¹ã¿å> --machine-type=f1-micro --num-nodes=1 --disk-size=10
確èªãã¦ã¿ãã
$ gcloud container node-pools list --cluster <ã¯ã©ã¹ã¿å> NAME MACHINE_TYPE DISK_SIZE_GB NODE_VERSION default-pool f1-micro 10 1.8.10-gke.0 <ãã¼ããã¼ã«å> f1-micro 10 1.8.10-gke.0
default-pool
ã¨ããã®ã preemptible ãªã¤ã³ã¹ã¿ã³ã¹ã®ãããããããã
次ã«ãpreemptible ã¤ã³ã¹ã¿ã³ã¹ãæ大24æéã§æ¶å¤±ãããåçãããããæ§åãè¦è¦çã«ç¢ºèªãã¦ã¿ããã®ã§ãmackerel-agent ã³ã³ãããåãã¼ãã«ã²ã¨ã¤ãã¤é ç½®ããï¼daemonsetï¼ã
以ä¸ã®ãã㪠yaml ãã¡ã¤ã«ãç¨æãã¦......
apiVersion: extensions/v1beta1 kind: DaemonSet metadata: labels: name: mackerel-agent name: mackerel-agent spec: template: metadata: labels: app: mackerel-agent spec: containers: - name: mackerel-agent image: mackerel/mackerel-agent:latest imagePullPolicy: Always env: - name: apikey value:<API KEY> - name: opts value: -role=<MACKEREL SERVICE NAME>:<MACKEREL ROLE NAME> - name: enable_docker_plugin value: "1" - name: auto_retirement value: "1" lifecycle: preStop: exec: command: ["/usr/bin/mackerel-agent", "retire", "-force"] volumeMounts: - name: docker-sock mountPath: /var/run/docker.sock - name: mackerel-id mountPath: /var/lib/mackerel-agent/ volumes: - name: docker-sock hostPath: path: /var/run/docker.sock - name: mackerel-id hostPath: path: /var/lib/mackerel-agent/
以ä¸ã®ã³ãã³ããå®è¡ã
$ kubectl create -f test.yaml
podã®ç¢ºèªã
$ kubectl get pods NAME READY STATUS RESTARTS AGE mackerel-agent-5lln2 1/1 Running 0 1m mackerel-agent-7ndm4 1/1 Running 0 1m mackerel-agent-9sb72 1/1 Running 0 1m mackerel-agent-jrshg 1/1 Running 0 1m
preemptible ãªã¤ã³ã¹ã¿ã³ã¹ x 3ããµã¤ãã®ã¤ã³ã¹ã¿ã³ã¹ x 1 ã®åè¨4ã¤ã³ã¹ã¿ã³ã¹ã«å¯¾ããdaemonset ã§å®è¡ããã®ã§åãã¼ã㧠mackerel-agent ã³ã³ãããåãã¦ããæ§åããããã
ãã®ç¶æ ã§æ°æéæ¾ç½®ãããã¨ã®ãMackerel ã®ã°ã©ãï¼ãã¼ã«ã°ã©ãï¼ã¯ã©ã¹ã¿å ¨ä½ã®æ¨ç§»ãã¿ãããï¼ã¯ä»¥ä¸ã®ãããªãããã
åè²ã§ç¤ºãããã®ã¯åã¤ã³ã¹ã¿ã³ã¹ã®ãªã½ã¼ã¹ç¶æ³ãpreemptible ãªã¤ã³ã¹ã¿ã³ã¹ãå ¥ã代ããç«ã¡ä»£ããã次ã ã¨ã·ã£ãããã¦ã³ï¼æ°ãã«èµ·åããã¤ã¤ããnot preemptible ãªã¤ã³ã¹ã¿ã³ã¹ã¯ç¨¼åãã¤ã¥ãã¦ããã®ãããããããããã
ãããè¦ã¦ãã¦ãµã¨æã£ããã©ãpreemptible ãªã¤ã³ã¹ã¿ã³ã¹ã使ããã¨ã§ chaos monkey çãªãããã«ãªã£ã¦éã«å¼·ãããªã£ã¦ãã®ã§ã¯ï¼ã¨ãæã£ãã......ã¨ããã®ã¯ããã¸ãã£ããããããï½
ã³ã¹ã
ãã¡ãã®ãã¼ã¸ ã«è¨è¼ã®ã¨ãããpreemptible 㪠f1-micro ã¤ã³ã¹ã¿ã³ã¹ã®1ã¶æã®éç¨ã³ã¹ã㯠$2.56 ï¼ãªã¬ã´ã³ãªã¼ã¸ã§ã³ï¼ãããã3å°ãªã®ã§ $7.68ãããã¦è¿½å ã®ãã¼ããã¼ã«ã§åã1å°ã® not preemptible ã¤ã³ã¹ã¿ã³ã¹ã¯ç¡ææ ãé©ç¨ãããã¯ããªã®ã§ç¡æã......ã¨ããããã§ã趣å³éçºç¨éã¨ãã¦ã¯è¨±å®¹ç¯å²ããªï¼ãã»ããheroku ã® Hobby dyno ã $7/month ã ãï¼ï¼ï¼ã
ã¡ãªã¿ã« g1-small ã n1-standard-1 ã®ãã·ã³ã¿ã¤ãã ã¨1å°ã§GKEã¯ã©ã¹ã¿ãä½ããã¨ãã§ãã¦ãããããã® preemptible æé㯠$5.11/month , $7.30/monthããªã®ã§ãã£ã¡ã§ãããã®ã§ã¯ï¼ã¨æãããã©ã1å°ã ã¨ãã¯ã©ã¹ã¿ãæããªãã®ããªããã¤ã ãããªã«ãã1å°ãããªãã®ã« preemptible æå®ããã¦ãã¾ãã¨ãã¦ã³ã¿ã¤ã ãçºçãã¦ãã¾ãã¨æãããã®ã§ã¡ãã£ã¨å¾®å¦ããªã¨æã£ã¦ããï¼ãã㦠preemptible ã«ããªãã¨ããããã®ã³ã¹ãã«ããªãï¼ã
ãã ããã®ã¯ã©ã¹ã¿ä¸ã§Webã¢ããªã±ã¼ã·ã§ã³ãªã©ãåããã¦ãããå¤é¨ããã¢ã¯ã»ã¹ã§ããããã«ãã¨ããããã¨ããã¨ãããã¨ã¯å¥ã«ãã¼ããã©ã³ãµã¼ã¨ã転ééè²»ç¨ãæããã¨æãã®ã§ããã®ç¹ã¯è¦æ³¨æï¼ãã¼ããã©ã³ãµã¼è²»ç¨ã®æ¹ãæ¯é çã«ãªããã ãããªããã£ã¨......ï¼ã
ï¼2018-06-21 追è¨ï¼ä¸è¨ã®æ§æã§æ°æ¥åããã¦ã¿ãã¨ãã®èª²éé¡ã以ä¸ã«è²¼ã£ã¦ããã
注æã¨ãé¡ã :pray:
ãã¼ããã¼ã«ã¨ãã®ç´°ããä»æ§ãå¶éã調ã¹ãããã¨ãªããããæ¸ãã¦ããã®ã§ãèæ ®æ¼ããªã©ãããããããªãã®ã§ããã¯æ³¨æãã¦ã»ããã®ã¨ããã£ã¨è³¢ãéç¨ã®ä»æ¹ãªã©ãããã°ãã²æãã¦ãã ãããåã¯ã趣å³éçºç¨éã¨ãã¦æ軽ã«ãããã試ããã¨ãã§ãã¦ãããã§ãã¦ã§ããã ãå®ããããã³ã³ãããªã¼ã±ã¹ãã¬ã¼ã·ã§ã³ç°å¢ï¼k8sç°å¢ï¼ãã»ãããããã ããã ãï¼
2018-06-25 追è¨
ãã®ã¯ã©ã¹ã¿ã使ã£ã¦ãå°ããªWebã¢ããªã±ã¼ã·ã§ã³ããããã¤ ï¼ HTTPS対å¿ããã£ã¦ã¿ã¾ããã