ãDocker for Macã«Kubernetesãè¼ã£ãã¨ãããã¨ã§ãä»åã¯è¤æ°ã®Podã®ãã°ãã¾ã¨ãã¦åç §ã§ããsternãç´¹ä»ã(åã ããæ¸ããã¨ã¯æã£ã¦ããã ãã©ãæ©ä¼ãé¸ãã¦ãããã ãã)
å°å ¥
ãMacãªãHomebrewããã¤ã³ã¹ãã¼ã«ã§ããã
$ brew install stern
ãµã³ãã«ã®ç¨æ
ãå®éã®ä½¿ãæ¹ã®åã«ä»¥ä¸ã®ãããªãµã³ãã«ãç¨æãã¦ã¿ããKuberneteã¸ã®Podã®å±éã¯ç¾å¨ã§ã¯Deploymentãç¨ãããã¨ãæ¨å¥¨ããã¦ããã®ã§ãã²ããããã°åºåããï¼ã¤ã®ã³ã³ããã«ãã£ã¦æ§æãããPodãï¼ã¤ãããã¤ãã¦ã¿ãã
# deployment.yaml apiVersion: apps/v1beta1 kind: Deployment metadata: name: sample spec: replicas: 3 template: metadata: labels: app: sample spec: containers: - name: sample-a image: busybox command: - sh - -c - while true; do echo $(hostname):a; sleep 10; done - name: sample-b image: busybox command: - sh - -c - while true; do echo $(hostname):b; sleep 10; done
$ kubectl create -f deployment.yml deployment "sample" created $ kubectl get all NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deploy/sample 3 3 3 0 7s NAME DESIRED CURRENT READY AGE rs/sample-7546bcdb67 3 3 0 7s NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE deploy/sample 3 3 3 0 7s NAME DESIRED CURRENT READY AGE rs/sample-7546bcdb67 3 3 0 7s NAME READY STATUS RESTARTS AGE po/sample-7546bcdb67-ndvln 0/2 ContainerCreating 0 7s po/sample-7546bcdb67-vj5fh 0/2 ContainerCreating 0 7s po/sample-7546bcdb67-zzv4f 0/2 ContainerCreating 0 7s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE svc/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 7d
ã³ã³ããã®ãã°ã確èªããã«ã¯ï¼
ããã¦ããããããããã¤ãããã³ã³ããã®ãã°ãè¦ããã¨ããå ´åã ç¹å®ã®PODå
ã®ã³ã³ããã§ããã°kubectl logs -f [POD] -c [CONTAINER]
ã«ãã£ã¦ããªããtail -f
ã®ããã«ãã°ç£è¦ããããã¨ãã§ããã
$ kubectl logs -f po/sample-7546bcdb67-ndvln -c sample-a sample-7546bcdb67-ndvln:a sample-7546bcdb67-ndvln:a sample-7546bcdb67-ndvln:a
ããã®æ¹æ³ã®å ´åã¯deploymentã«ãã£ã¦ä½ãããPODã®ååã¯å¤ãã£ã¦ãã¾ãã®ã§æ¯åº¦ç¢ºèªããªãã¨ãããªãã®ãã¡ããé¢åã
ãã¾ããkubectl logs -l[METADATA] -c [CONTAINER]
ã«ãã£ã¦ç¹å®ã®ã¡ã¿ãã¼ã¿ãæã£ãPODã®ç¹å®ã®ã³ã³ããã«ã¤ãã¦æ¨ªæçã«ãã°ãåç
§ãããã¨ãã§ããã
$ kubectl logs -lapp=sample -c sample-a sample-7546bcdb67-ndvln:a sample-7546bcdb67-vj5fh:a sample-7546bcdb67-zzv4f:a
ããã ããããã¯ä¸ããé ã«åç §ãããã°ãç¹ããã ãã®ãã®ãªã®ã§æç³»åãæ´ããªãã®ã«æ³¨æã
ãkubectl logs
ã³ãã³ãã§ã¯docker-compose logs
ã®ãããªããªã§è¤æ°ã®ã³ã³ãããåæã«åç
§ãããã¨ã¯ã§ããªããã-l
ãªãã·ã§ã³ã¨-f
ãªãã·ã§ã³ãä½µç¨ãããã¨ãã§ããªãã®ãéçºæã«ä¸ä¾¿ã ã£ããããã
sternã®ä½¿ãæ¹
ããããªããã§æ¬é¡ããããªè¤æ°ã®POD/ã³ã³ããã§æ§æãããã·ã¹ãã ã®ãã°ã横æçã«ç£è¦ãããå ´åã«ä¾¿å©ãªã®ãä»åã®sternã
ãä¸çªã·ã³ãã«ãªä½¿ãæ¹ã¨ãã¦ãä»åãããã¤ããå
¨ã¦ã®PODã®ãã°ã§ããã°starn [POD_QUERY]
ã®å½¢ã§åç
§ã§ããã
$ stern sam sample-7546bcdb67-vj5fh sample-a sample-7546bcdb67-vj5fh:a sample-7546bcdb67-vj5fh sample-a sample-7546bcdb67-vj5fh:a sample-7546bcdb67-zzv4f sample-b sample-7546bcdb67-zzv4f:b sample-7546bcdb67-zzv4f sample-a sample-7546bcdb67-zzv4f:a
ãã¡ãªã¿ã«ãã®æã®æå®ã¯PODåã¯å ¨æã§ããå¿ è¦ã¯ç¡ãã¦PODåã®ä¸é¨ã§è¯ããã¤ã¾ããã£ã¨è¤éãªPODã«ãã£ã¦æ§æãããã·ã¹ãã ãªããã§æ¨ªæçã«åç §ããéã«ã使ããã
ãã¾ãã-l
ãªãã·ã§ã³ã«ããã¡ã¿ãã¼ã¿ãã-c
ãªãã·ã§ã³ã«ããã³ã³ãããéå®ãããã¨ãã§ããã
$ stern -lapp=sample -c .*b sample-7546bcdb67-ndvln sample-b sample-7546bcdb67-ndvln:b sample-7546bcdb67-ndvln sample-b sample-7546bcdb67-ndvln:b sample-7546bcdb67-zzv4f sample-b sample-7546bcdb67-zzv4f:b sample-7546bcdb67-zzv4f sample-b sample-7546bcdb67-zzv4f:b
ãä»ã«ã-t
ã«ããã¿ã¤ã ã¹ã¿ã³ãä»å ãªã©ã§ããã
ããããªæãã§ãsternãæ´»ç¨ãããã¨ã«ãã£ã¦Docker Composeã®ãããªè»½ãããã§Kubernetesç°å¢ã§ã®éçºãè¡ããã¨ãã§ããã
- ä½è : ?æ©å¥ä¸,è°·å£ç¦è±,äºæ¬å¤§ç»,å±±å´åå¹³,大åç°ç´,å æå 樹,åæ±æå,å¹³ç°æä¹,ç§å¤§è¼,æ¿æ·åº·æ´,大?浩å´,ç©´äºå®å¹¸,åå£å®æ,ä¹ ç°çå¯,ãµãã¯ããã,ã®ããã²ããµã¿,ãããã¿,ã²ãã½ã,æ± ç°æå¸,ã¯ã¾ã¡ã2,竹å,çç°é樹,æ¸æ±ä¸æ,WEB+DB PRESSç·¨éé¨ç·¨
- åºç社/ã¡ã¼ã«ã¼: æè¡è©è«ç¤¾
- çºå£²æ¥: 2017/06/24
- ã¡ãã£ã¢: 大åæ¬
- ãã®ååãå«ãããã°ãè¦ã