來自 谷歌雲平臺官方博客 的消息:CoreOS 的 CTO —— Brandon Philips 宣布 Google 的 Compute Engine 平臺已經提供了 CoreOS 系統的支持。CoreOS 可輕鬆的與 Google 的負載均衡和 replica pools 集成,實現應用程式跨區域的伸縮。
CoreOS 使用 cloud-config 來配置機器啟動後的自動集群:
$ curl https://discovery.etcd.io/newhttps://discovery.etcd.io/b97f446100a293c8107500e11c34864b
在你的 cloud-config 文檔中設置發現 token
$ cat cloud-config.yaml#cloud-configcoreos: etcd: # generate a new token for each unique cluster from https://discovery.etcd.io/new discovery: https://discovery.etcd.io/b97f446100a293c8107500e11c34864b # multi-region and multi-cloud deployments need to use $public_ipv4 addr: $private_ipv4:4001 peer-addr: $private_ipv4:7001 units: - name: etcd.service command: start - name: fleet.service command: start
在生成 cloud-config 後便可通過一個命令啟動3臺機器的集群,記住要替換你的項目 id:
gcutil --project=<project-id> addinstance--image=projects/coreos-cloud/global/images/coreos-beta-310-1-0-v20140508 --persistent_boot_disk --zone=us-central1-a --machine_type=n1-standard-1 --metadata_from_file=user-data:cloud-config.yaml core1 core2 core3
為了展示快速的調度能力,我們提交並啟動一個很簡單的 Docker 容器並顯示一條消息,首先 SSH 登錄其中一臺機器,記住替換你的項目 id
$ gcutil --project=coreos ssh --ssh_user=core core1
創建一個單元文件並在容器中運行
$ cat example.service[Unit]Description=MyAppAfter=docker.serviceRequires=docker.service[Service]RemainAfterExit=yesExecStart=/usr/bin/docker run busybox /bin/echo 'I was scheduled with fleet!'
為了在新的集群上運行單元文件,可通過 fleetctl 來提交:
$ fleetctl start example.service$ fleetctl list-unitsUNIT STATE LOAD ACTIVE SUB DESC MACHINEexample.service launched loaded active exited MyApp b603fc4d.../10.240.246.57
可通過 feetctl 輕鬆獲取註冊表容器的狀態:
$ fleetctl status example.service● example.service - MyApp Loaded: loaded (/run/fleet/units/example.service; linked-runtime) Active: active (exited) since Thu 2014-05-22 20:27:54 UTC; 4s ago Process: 15789 ExecStart=/usr/bin/docker run busybox /bin/echo I was scheduled with fleet! (code=exited, status=0/SUCCESS) Main PID: 15789 (code=exited, status=0/SUCCESS)May 22 20:27:54 core-01 systemd[1]: Started MyApp.May 22 20:27:57 core-01 docker[15789]: I was scheduled with fleet!
使用這些基礎的工具你可以輕鬆創建基於 CoreOS 的完全分布式應用,可通過 CoreOS blog 獲取更多關於使用 fleet、負載均衡等方面的示例。完整的在 Compute Engine 運行 CoreOS 的文檔請參考 head over to the docs.