有趣的Google container-vm

研究Google在GCE執行datalab的範例中,發現了個頗有趣的事情... 不久前Google針對Optimized Container出了一個container-vm,雖然目前已經預計要deprecate這個image,不過在datalab執行於GCE的範例中M還是使用這個image來執行...
有趣的地方是,datalab-service.yaml是一個k8s的pod描述檔... 下面是instance執行的gcloud腳本:
gcloud compute instances create "instance-name" \
  --project "project-id" \
  --zone "zone" \
  --network "datalab-network" \
  --image-family "container-vm" \
  --image-project "google-containers" \
  --metadata-from-file "google-container-manifest=datalab-server.yaml" \
  --machine-type "n1-highmem-2" \
  --scopes "cloud-platform"
打開datalab-server.yaml檢視,內容如下:
apiVersion: v1
kind: Pod
metadata:
  name: 'datalab-server'
spec:
  containers:
    - name: datalab
      image: gcr.io/cloud-datalab/datalab:local
      command: ['/datalab/run.sh']
      imagePullPolicy: Always
      ports:
        - containerPort: 8080
          hostPort: 8080
          hostIP: 127.0.0.1
      env:
        - name: DATALAB_ENV
          value: GCE
      volumeMounts:
        - name: home
          mountPath: /content
    - name: logger
      image: gcr.io/google_containers/fluentd-gcp:1.18
      env:
        - name: FLUENTD_ARGS
          value: -q
      volumeMounts:
        - name: varlog
          mountPath: /var/log
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
  volumes:
    - name: home
      hostPath:
        path: /root
    - name: varlog
      hostPath:
        path: /var/log
    - name: varlibdockercontainers
      hostPath:
        path: /var/lib/docker/containers
這本身是個k8s pod的描述檔,本來需要透過kubernetes cluster才能夠執行,但是卻可以在container-vm中執行... 檢查了一下,原來是透過kubelet來執行... 研究一下kubelet執行container的方式,目前找到可以在/etc/kubernetes/manifests下面直接放置yaml檔案,然後重啟kubelet(/etc/init.d/kubelet restart)即可。

Reference

Latest