Build your first application from top to bottom on CoreOS

[Editor's Note] The author to their own Mac notebook, for example, describes how to install WordPress application on the CoreOS, not too much theoretical explanation, all the actual class tutorial, recommended to quickly understand CoreOS students to read.

I believe you must have heard of CoreOS , but do you really have an application on it? There may be many people have not deployed. It is very difficult and frustrating to build an application on CoreOS. Because the document is scattered, and you have to learn all the relevant technologies before you start, including etcd, systemd, Docker. If you and I are more lazy, just want to try CoreOS and do not want to fuss, then let me help you Next we will create a simple WordPress application and a MySQL database on CoreOS.
Screen-Shot-2014-03-25-at-2.13_.49-PM_.png

If you are using a Mac, you can control the CoreOS by installing command line tools

fleetctl and etcdctl are native tools for controlling CoreOS clusters. The installation steps are as follows:

$ brew install go etcdctl
$ git clone https://github.com/coreos/fleet.git
$ cd fleet
$ ./build
$ mv bin/fleetctl /usr/local/bin/

Install a local CoreOS cluster and run it

Vagrant is very simple.
$ git clone https://github.com/CenturyLinkLabs/coreos-vagrant
$ cd coreos-vagrant/cluster
$ vagrant up --provision

Now your notebook has a cluster of three smallest CoreOS systems. Very simple, and now let us use fleetctl to check the next.
$ fleetctl list-machines
MACHINE IP METADATA
09fd0a88... 10.0.2.15 -
77763947... 10.0.2.15 -
f31c383c... 10.0.2.15 -

It was great and got up.

Use fleet to deploy applications on a CoreOS cluster

Now you have a CoreOS cluster. The next fleetctl command allows you to deploy the application on the CoreOS cluster node, but use the fleet to write the service file. Of course, you do not need to write your own. You can use the simple YAML format to generate a service file.

  $ Sudo gem install bundler fig2coreos 

$ Cat fig.yml
Web:
Image: ctlc / wordpress
Ports:
- 80:80
Environment:
DB_USER: root
DB_PASSWORD: qa1N76pWAri9
Links:
- db
Db:
Image: ctlc / mysql
Ports:
- 3306: 3306
Environment:
MYSQL_DATABASE: wordpress
MYSQL_ROOT_PASSWORD: qa1N76pWAri9

$ Fig2coreos myapp fig.yml coreos-files

$ Cd coreos-files

$ Ls
Db-discovery.1.service
Db.1.service
Web-discovery.1.service
Web.1.service

fleetctl client tool uses the key store of etcd to determine which server it wants to access and access the server in the cluster where the etcd server is running. Here's how to deploy your application in a CoreOS cluster.

  $ Fleetctl start db.1.service 

$ Fleetctl list-units
UNIT LOAD ACTIVE SUB DESC MACHINE
Db.1.service loaded active running Run db_1 9c008961 ... / 10.0.2.15

$ Fleetctl start web.1.service

$ Fleetctl list-units
UNIT LOAD ACTIVE SUB DESC MACHINE
Db.1.service loaded active running Run db_1 9c008961 ... / 10.0.2.15
Web.1.service loaded active running web_1 9c008961 ... / 10.0.2.15

Now your program is running, but the service has not been registered to etcd . Fortunately, fig2coreos has automatically generated service files for us.

  $ Fleetctl start db-discovery.1.service 
$ Fleetctl start web-discovery.1.service

$ Fleetctl list-units
UNIT LOAD ACTIVE SUB DESC MACHINE
Db-discovery.1.service loaded active running Announce db_1 9c008961 ... / 10.0.2.15
Db.1.service loaded active running Run db_1 9c008961 ... / 10.0.2.15
Web-discovery.1.service loaded active running Announce web_1 9c008961 ... / 10.0.2.15
Web.1.service loaded active running web_1 9c008961 ... / 10.0.2.15

$ Etcdctl ls --recursive
/ Services
/ Services / web
/ Services / web / web_1
/ Services / db
/ Services / db / db_1

$ Etcdctl get / services / web / web_1
{"Host": "core-03", "port": 80, "version": "52c7248a14"}

$ Etcdctl get / services / db / db_1
{"Host": "core-03", "port": 3306, "version": "52c7248a14"}

Deployment is complete

In this way, get it. In Vagrant 1.5 using the Vagrant Cloud account, you can access your WordPress app. As shown below:

  $ Cd ~ / coreos-vagrant / cluster / 

Find out which box is hosting your port

$ Etcdctl get / services / web / web_1
{"Host": "core-03", "port": 80, "version": "52c7248a14"}

$ Vagrant share core-03 - http 80
==> core-03: Detecting network information for machine ...
Core-03: Local machine address: 192.168.65.2
Core-03: Local HTTP port: 80
Core-03: Local HTTPS port: disabled
==> core-03: Checking authentication and authorization ...
==> core-03: Creating Vagrant Share session ...
Core-03: Share will be at: quick-iguana-4689
==> core-03: Your Vagrant Share is running! Name: quick-iguana-4689
==> core-03: URL: http://quick-iguana-4689.vagrantshare.com

Screen-Shot-2014-03-25-at-1.58_.16-PM_.png

in conclusion

Now you can do a lot of things with CoreOS, but at least now you have done the basic work, if you intend to use the multi-host Coreos cluster in the production environment. You need to increase the ambassador container in the system. In fact, you can connect the server through the ambassador container, we will be published next week, another blog post.

Original Address: http://newlabs.wpengine.com/bu … reos /

    Heads up! This alert needs your attention, but it's not super important.