[Tutorial] Build your first application on CoreOS
[Editor's note] the author uses his Mac notebook as an example to introduce how to install the WordPress application on CoreOS. There is not much theoretical explanation. It is a practical tutorial, we recommend that you want to quickly learn about CoreOS.
I believe you have heard of CoreOS, but have you actually deployed an application on it? Many people may not have deployed the service. It is very difficult and frustrating to build an application on CoreOS ). Because documents are scattered and you have to learn all the related technologies before you start, including etcd, systemd, and Docker. If you are just as lazy as you are, you just want to try CoreOS and don't want to worry about it, so let me help you. Next, we will create a simple WordPress application and MySQL database on CoreOS.
If you are using a Mac, you can install the command line tool to control CoreOS
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
Vagrant is very simple.
- $ Git clone https://github.com/CenturyLinkLabs/coreos-vagrant
$ Cd coreos-vagrant/cluster
- $ Vagrant up -- provision
Your notebook now has a cluster consisting of the smallest three CoreOS systems. It's very simple. Now let's use fleetctl to check.
- $ Fleetctl list-machines MACHINE IP METADATA
- 09fd0a88... 10.0.2.15-
- 77763947... 10.0.2.15-
- F31c383c... 10.0.2.15-
It's great. It's running.
Deploy applications on CoreOS cluster using fleet
Now you have a CoreOS cluster. Next, the fleetctl command allows you to deploy applications on CoreOS cluster nodes, but you need to use fleet to write service files. Of course, you do not need to write it yourself. You can generate service files in a simple YAML format.
$ 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
The fleetctl client tool uses the key-value storage of etcd to determine the server to be accessed and the server running on the etcd server in the access cluster. The following describes how to deploy your application in the CoreOS cluster.
$ fleetctl start db.1.service$ fleetctl list-unitsUNIT LOAD ACTIVE SUB DESC MACHINEdb.1.service loaded active running Run db_1 9c008961.../10.0.2.15$ fleetctl start web.1.service$ fleetctl list-unitsUNIT LOAD ACTIVE SUB DESC MACHINEdb.1.service loaded active running Run db_1 9c008961.../10.0.2.15web.1.service loaded active running Run 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-unitsUNIT LOAD ACTIVE SUB DESC MACHINEdb-discovery.1.service loaded active running Announce db_1 9c008961.../10.0.2.15db.1.service loaded active running Run db_1 9c008961.../10.0.2.15web-discovery.1.service loaded active running Announce web_1 9c008961.../10.0.2.15web.1.service loaded active running Run 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 completed
That's it. You can use the Vagrant Cloud account in Vagrant 1.5 to access your WordPress application. For example:
$ cd ~/coreos-vagrant/cluster/
Find out which machine is listening to your port 80:
$ 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.2core-03: Local HTTP port: 80core-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
Conclusion
Now you can use CoreOS to do a lot of things, but at least now you have done the basic work, if you plan to use multi-host Coreos cluster in the production environment. You need to add the ambassador container to the system. In fact, you can connect to the etc server through the ambassador container. We will post another blog article next week.
How to deploy a WordPress instance in CoreOS
Initial server operating system CoreOS experience
CoreOS practice: Introduction to CoreOS and management tools
CoreOS details: click here
CoreOS: click here
Http://newlabs.wpengine.com/building-your-first-app-on-coreos/ Author: Lucas Carlson
Http://dockerone.com/article/66.
This article permanently updates the link address: