2015-07-12 12:04:52 +08:00
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- BEGIN STRIP_FOR_RELEASE -->
2015-07-17 01:02:26 +08:00
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
< img src = "http://kubernetes.io/img/warning.png" alt = "WARNING"
width="25" height="25">
2015-07-14 06:15:35 +08:00
2015-07-17 01:02:26 +08:00
< h2 > PLEASE NOTE: This document applies to the HEAD of the source tree< / h2 >
2015-07-12 12:04:52 +08:00
2015-07-17 01:02:26 +08:00
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
2015-07-12 12:04:52 +08:00
2015-07-17 01:02:26 +08:00
< strong >
The latest 1.0.x release of this document can be found
[here ](http://releases.k8s.io/release-1.0/docs/getting-started-guides/coreos/azure/README.md ).
Documentation for other releases can be found at
[releases.k8s.io ](http://releases.k8s.io ).
< / strong >
--
2015-07-14 06:15:35 +08:00
2015-07-12 12:04:52 +08:00
<!-- END STRIP_FOR_RELEASE -->
<!-- END MUNGE: UNVERSIONED_WARNING -->
2015-06-23 03:39:35 +08:00
Kubernetes on Azure with CoreOS and [Weave ](http://weave.works )
---------------------------------------------------------------
2015-02-17 22:16:38 +08:00
2015-06-23 03:39:35 +08:00
**Table of Contents**
2015-06-23 02:56:19 +08:00
2015-06-23 23:20:31 +08:00
- [Introduction ](#introduction )
- [Prerequisites ](#prerequisites )
- [Let's go! ](#lets-go )
- [Deploying the workload ](#deploying-the-workload )
- [Scaling ](#scaling )
- [Exposing the app to the outside world ](#exposing-the-app-to-the-outside-world )
- [Next steps ](#next-steps )
- [Tear down... ](#tear-down )
2015-06-23 02:56:19 +08:00
2015-02-17 22:16:38 +08:00
## Introduction
2015-02-20 17:11:25 +08:00
In this guide I will demonstrate how to deploy a Kubernetes cluster to Azure cloud. You will be using CoreOS with Weave, which implements simple and secure networking, in a transparent, yet robust way. The purpose of this guide is to provide an out-of-the-box implementation that can ultimately be taken into production with little change. It will demonstrate how to provision a dedicated Kubernetes master and etcd nodes, and show how to scale the cluster with ease.
2015-02-17 22:16:38 +08:00
2015-06-23 03:39:35 +08:00
### Prerequisites
2015-07-18 06:35:41 +08:00
2015-06-23 03:39:35 +08:00
1. You need an Azure account.
2015-02-17 22:16:38 +08:00
## Let's go!
2015-02-20 17:11:25 +08:00
To get started, you need to checkout the code:
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```sh
2015-09-03 22:10:11 +08:00
git clone https://github.com/kubernetes/kubernetes
2015-02-20 17:11:25 +08:00
cd kubernetes/docs/getting-started-guides/coreos/azure/
2015-02-17 22:16:38 +08:00
```
You will need to have [Node.js installed ](http://nodejs.org/download/ ) on you machine. If you have previously used Azure CLI, you should have it already.
2015-02-20 17:11:25 +08:00
First, you need to install some of the dependencies with
2015-02-17 22:16:38 +08:00
2015-07-19 10:20:04 +08:00
```sh
2015-02-17 22:16:38 +08:00
npm install
```
Now, all you need to do is:
2015-07-19 10:20:04 +08:00
```sh
2015-06-01 20:23:13 +08:00
./azure-login.js -u < your_username >
2015-02-17 22:16:38 +08:00
./create-kubernetes-cluster.js
```
2015-07-13 12:15:58 +08:00
This script will provision a cluster suitable for production use, where there is a ring of 3 dedicated etcd nodes: 1 kubernetes master and 2 kubernetes nodes. The `kube-00` VM will be the master, your work loads are only to be deployed on the nodes, `kube-01` and `kube-02` . Initially, all VMs are single-core, to ensure a user of the free tier can reproduce it without paying extra. I will show how to add more bigger VMs later.
2015-02-17 22:16:38 +08:00
2015-02-20 17:11:25 +08:00

2015-02-17 22:16:38 +08:00
Once the creation of Azure VMs has finished, you should see the following:
2015-07-19 10:20:04 +08:00
```console
2015-02-17 22:16:38 +08:00
...
2015-06-01 20:23:13 +08:00
azure_wrapper/info: Saved SSH config, you can use it like so: `ssh -F ./output/kube_1c1496016083b4_ssh_conf <hostname>`
2015-02-17 22:16:38 +08:00
azure_wrapper/info: The hosts in this deployment are:
[ 'etcd-00', 'etcd-01', 'etcd-02', 'kube-00', 'kube-01', 'kube-02' ]
2015-06-01 20:23:13 +08:00
azure_wrapper/info: Saved state into `./output/kube_1c1496016083b4_deployment.yml`
2015-02-17 22:16:38 +08:00
```
Let's login to the master node like so:
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```sh
2015-06-01 20:23:13 +08:00
ssh -F ./output/kube_1c1496016083b4_ssh_conf kube-00
2015-02-17 22:16:38 +08:00
```
2015-07-17 10:01:02 +08:00
2015-02-17 22:16:38 +08:00
> Note: config file name will be different, make sure to use the one you see.
2015-06-01 20:23:13 +08:00
Check there are 2 nodes in the cluster:
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```console
2015-06-01 20:23:13 +08:00
core@kube-00 ~ $ kubectl get nodes
2015-07-18 00:35:55 +08:00
NAME LABELS STATUS
kube-01 kubernetes.io/hostname=kube-01 Ready
kube-02 kubernetes.io/hostname=kube-02 Ready
2015-02-17 22:16:38 +08:00
```
## Deploying the workload
Let's follow the Guestbook example now:
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```sh
2015-07-18 00:35:55 +08:00
kubectl create -f ~/guestbook-example
2015-02-17 22:16:38 +08:00
```
2015-07-18 00:35:55 +08:00
You need to wait for the pods to get deployed, run the following and wait for `STATUS` to change from `Pending` to `Running` .
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```sh
2015-02-17 22:16:38 +08:00
kubectl get pods --watch
```
2015-07-17 10:01:02 +08:00
2015-06-01 20:23:13 +08:00
> Note: the most time it will spend downloading Docker container images on each of the nodes.
2015-02-17 22:16:38 +08:00
Eventually you should see:
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```console
2015-07-18 00:35:55 +08:00
NAME READY STATUS RESTARTS AGE
frontend-0a9xi 1/1 Running 0 4m
frontend-4wahe 1/1 Running 0 4m
frontend-6l36j 1/1 Running 0 4m
redis-master-talmr 1/1 Running 0 4m
redis-slave-12zfd 1/1 Running 0 4m
redis-slave-3nbce 1/1 Running 0 4m
2015-02-17 22:16:38 +08:00
```
## Scaling
2015-07-18 00:35:55 +08:00
Two single-core nodes are certainly not enough for a production system of today. Let's scale the cluster by adding a couple of bigger nodes.
2015-02-17 22:16:38 +08:00
2015-07-18 00:35:55 +08:00
You will need to open another terminal window on your machine and go to the same working directory (e.g. `~/Workspace/kubernetes/docs/getting-started-guides/coreos/azure/` ).
2015-02-17 22:16:38 +08:00
First, lets set the size of new VMs:
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```sh
2015-02-17 22:16:38 +08:00
export AZ_VM_SIZE=Large
```
2015-07-17 10:01:02 +08:00
2015-06-01 20:23:13 +08:00
Now, run scale script with state file of the previous deployment and number of nodes to add:
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```console
core@kube-00 ~ $ ./scale-kubernetes-cluster.js ./output/kube_1c1496016083b4_deployment.yml 2
2015-02-17 22:16:38 +08:00
...
2015-06-01 20:23:13 +08:00
azure_wrapper/info: Saved SSH config, you can use it like so: `ssh -F ./output/kube_8f984af944f572_ssh_conf <hostname>`
2015-02-17 22:16:38 +08:00
azure_wrapper/info: The hosts in this deployment are:
[ 'etcd-00',
'etcd-01',
'etcd-02',
'kube-00',
'kube-01',
'kube-02',
'kube-03',
'kube-04' ]
2015-06-01 20:23:13 +08:00
azure_wrapper/info: Saved state into `./output/kube_8f984af944f572_deployment.yml`
2015-02-17 22:16:38 +08:00
```
2015-07-17 10:01:02 +08:00
2015-02-17 22:16:38 +08:00
> Note: this step has created new files in `./output`.
Back on `kube-00` :
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```console
2015-06-01 20:23:13 +08:00
core@kube-00 ~ $ kubectl get nodes
2015-07-18 00:35:55 +08:00
NAME LABELS STATUS
kube-01 kubernetes.io/hostname=kube-01 Ready
kube-02 kubernetes.io/hostname=kube-02 Ready
kube-03 kubernetes.io/hostname=kube-03 Ready
kube-04 kubernetes.io/hostname=kube-04 Ready
2015-02-17 22:16:38 +08:00
```
2015-06-01 20:23:13 +08:00
You can see that two more nodes joined happily. Let's scale the number of Guestbook instances now.
2015-02-17 22:16:38 +08:00
First, double-check how many replication controllers there are:
2015-07-19 10:20:04 +08:00
```console
2015-02-17 22:16:38 +08:00
core@kube-00 ~ $ kubectl get rc
2015-07-18 00:35:55 +08:00
ONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
2015-06-01 20:23:13 +08:00
frontend php-redis kubernetes/example-guestbook-php-redis:v2 name=frontend 3
redis-master master redis name=redis-master 1
2015-07-18 00:35:55 +08:00
redis-slave worker kubernetes/redis-slave:v2 name=redis-slave 2
2015-02-17 22:16:38 +08:00
```
2015-07-17 10:01:02 +08:00
2015-06-01 20:23:13 +08:00
As there are 4 nodes, let's scale proportionally:
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```console
2015-07-18 00:35:55 +08:00
core@kube-00 ~ $ kubectl scale --replicas=4 rc redis-slave
>>>>>>> coreos/azure: Updates for 1.0
2015-05-22 05:10:25 +08:00
scaled
2015-07-18 00:35:55 +08:00
core@kube-00 ~ $ kubectl scale --replicas=4 rc frontend
2015-05-22 05:10:25 +08:00
scaled
2015-02-17 22:16:38 +08:00
```
2015-07-17 10:01:02 +08:00
2015-02-20 17:11:25 +08:00
Check what you have now:
2015-07-17 10:01:02 +08:00
2015-07-19 10:20:04 +08:00
```console
2015-06-01 20:23:13 +08:00
core@kube-00 ~ $ kubectl get rc
CONTROLLER CONTAINER(S) IMAGE(S) SELECTOR REPLICAS
frontend php-redis kubernetes/example-guestbook-php-redis:v2 name=frontend 4
redis-master master redis name=redis-master 1
2015-07-18 00:35:55 +08:00
redis-slave worker kubernetes/redis-slave:v2 name=redis-slave 4
2015-02-17 22:16:38 +08:00
```
2015-06-05 23:35:17 +08:00
You now will have more instances of front-end Guestbook apps and Redis slaves; and, if you look up all pods labeled `name=frontend` , you should see one running on each node.
2015-02-17 22:16:38 +08:00
2015-07-19 10:20:04 +08:00
```console
2015-02-17 22:16:38 +08:00
core@kube-00 ~/guestbook-example $ kubectl get pods -l name=frontend
2015-07-09 02:46:12 +08:00
NAME READY STATUS RESTARTS AGE
2015-07-18 00:35:55 +08:00
frontend-0a9xi 1/1 Running 0 22m
frontend-4wahe 1/1 Running 0 22m
frontend-6l36j 1/1 Running 0 22m
frontend-z9oxo 1/1 Running 0 41s
2015-02-17 22:16:38 +08:00
```
## Exposing the app to the outside world
2015-08-10 02:18:06 +08:00
There is no native Azure load-balancer support in Kubernetes 1.0, however here is how you can expose the Guestbook app to the Internet.
2015-02-20 17:11:25 +08:00
2015-07-18 00:35:55 +08:00
```
./expose_guestbook_app_port.sh ./output/kube_1c1496016083b4_ssh_conf
Guestbook app is on port 31605, will map it to port 80 on kube-00
info: Executing command vm endpoint create
+ Getting virtual machines
+ Reading network configuration
+ Updating network configuration
info: vm endpoint create command OK
info: Executing command vm endpoint show
+ Getting virtual machines
data: Name : tcp-80-31605
data: Local port : 31605
data: Protcol : tcp
data: Virtual IP Address : 137.117.156.164
data: Direct server return : Disabled
info: vm endpoint show command OK
```
2015-02-20 17:11:25 +08:00
2015-07-18 00:35:55 +08:00
You then should be able to access it from anywhere via the Azure virtual IP for `kube-00` displayed above, i.e. `http://137.117.156.164/` in my case.
2015-02-20 17:11:25 +08:00
## Next steps
You now have a full-blow cluster running in Azure, congrats!
2015-02-17 22:16:38 +08:00
2015-07-10 09:02:10 +08:00
You should probably try deploy other [example apps ](../../../../examples/ ) or write your own ;)
2015-02-17 22:16:38 +08:00
2015-02-20 17:11:25 +08:00
## Tear down...
2015-02-17 22:16:38 +08:00
2015-02-20 17:11:25 +08:00
If you don't wish care about the Azure bill, you can tear down the cluster. It's easy to redeploy it, as you can see.
2015-02-17 22:16:38 +08:00
2015-07-19 10:20:04 +08:00
```sh
2015-06-01 20:23:13 +08:00
./destroy-cluster.js ./output/kube_8f984af944f572_deployment.yml
2015-02-17 22:16:38 +08:00
```
2015-05-22 05:10:25 +08:00
> Note: make sure to use the _latest state file_, as after scaling there is a new one.
2015-02-17 22:16:38 +08:00
2015-02-20 17:11:25 +08:00
By the way, with the scripts shown, you can deploy multiple clusters, if you like :)
2015-05-15 06:12:45 +08:00
2015-07-14 08:13:09 +08:00
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
2015-05-15 06:12:45 +08:00
[]()
2015-07-14 08:13:09 +08:00
<!-- END MUNGE: GENERATED_ANALYTICS -->