Skip to content

Commit

Permalink
Merge pull request kubernetes#620 from keontang/caicloud-rebase-1.3.3…
Browse files Browse the repository at this point in the history
…-aliyun-ansible-deployment

add ansible deployment for aliyun instances to rebase 1.3.3
  • Loading branch information
ddysher authored and keontang committed Feb 7, 2017
2 parents ae65d44 + a6138b4 commit 30259bc
Show file tree
Hide file tree
Showing 68 changed files with 1,685 additions and 102 deletions.
2 changes: 2 additions & 0 deletions cluster/caicloud-aliyun/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
assignees:
- keontang
70 changes: 70 additions & 0 deletions cluster/caicloud-aliyun/README-ALIYUN-INSTANCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Aliyun instance Ansible

This playbook and set of roles set up aliyun instances for a kubernetes cluster.

## Before starting

* Record the aliyun access key id and access key secret.
* Record the number of kubernetes minion nodes, default 2 minion nodes (Only one master support).
* Make sure the version of your ansible running machine is equal to or greater than 2.1.0.0 and python-netaddr installed.

## Setup

### Configure Aliyun instances options

There are various places to configure aliyun instances:

- `group_vars/all.yml`: contains options each role will use, namely aliyun access key id, access key secret, security group name and aliyun region id.

- `roles/ntpdate/default/main.yml`: contains options for ntpdate to sync the linux server time with network time servers.

- `roles/aliyuncli/default/main.yml`: contains options for aliyuncli tool.

- `roles/up/default/main.yml`: contains options for creating aliyun instances.

- `roles/down/default/main.yml`: contains options for deleting aliyun instances.

The options are described there in full detail.

## Running the playbook

### Create aliyun instances

After going through the setup, run the following command to create aliyun instances:

```
ansible-playbook -v --extra-vars="access_key_id=XXXX access_key_secret=YYYY" cluster/caicloud-aliyun/run.yml
```

or put environment variables in a json file, for example `extra_vars.json`:
```
{
"access_key_id": "XXXX",
"access_key_secret": "YYYY",
"minion_node_num": 3
}
```

and then run the following command:

```
ansible-playbook -v --extra-vars "@extra_vars.json" cluster/caicloud-aliyun/run.yml
```

### Delete aliyun instances

If we want to delete aliyun instances, make sure set `delete_instance_flag="YES"` (refer to `roles/down/default/main.yml`), then run the following command:

```
ansible-playbook -v cluster/caicloud-aliyun/delete.yml
```

For example:

```
ansible-playbook -v --extra-vars="access_key_id=XXXX access_key_secret=YYYY delete_instance_flag=YES" cluster/caicloud-aliyun/delete.yml
```

It will delete all the instances in the aliyun security group (refer to `group_vars/all.yml`).

This will work on Ubuntu and CentOS.
124 changes: 124 additions & 0 deletions cluster/caicloud-aliyun/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Caicloud aliyun cloudprovider

Aliyun cloudprovider provides an ansible deployment of aliyun instances and kubernetes cluster.

## Set environment variables

### Required
We must set the following two environment variables:
```
ACCESS_KEY_ID
ACCESS_KEY_SECRET
User aliyun account information, required to access aliyun cloud service.
```

### Optional

```
NUM_NODES
The number of aliyun instances for kubernetes minion nodes. Default: 2
AUTOMATICALLY_INSTALL_TOOLS
`Ansible`, `aliyuncli` and there `dependencies` will not be installed by default, namely: `AUTOMATICALLY_INSTALL_TOOLS="NO"`. If you want to install them automatically, you need to set: `AUTOMATICALLY_INSTALL_TOOLS="YES"`.
DNS_HOST_NAME
Let you reach the kubernetes cluster by host name. For example, if DNS_HOST_NAME is `test` and BASE_DOMAIN_NAME is `caicloudapp.com`, we will access the kubernetes cluster by `https://test.caicloudapp.com`.
Default value is "caicloudstack".
BASE_DOMAIN_NAME
For example: caicloudapp.com.
Default value is "caicloudapp.com".
Required: USER_CERT_DIR.
USER_CERT_DIR
User certificates directory, including ca.crt, master.crt, master.key. Required: BASE_DOMAIN_NAME
DOMAIN_NAME_IN_DNS
Determine whether to process domain name (${DNS_HOST_NAME}.${BASE_DOMAIN_NAME}) in aliyun dns when kube-up and kube-down.
If `DOMAIN_NAME_IN_DNS == YES`, domain name will be added/deleted when kube-up/kube-down.
Default value is `YES` (valid value: `YES/NO`).
CAICLOUD_ACCESS_KEY_ID
CAICLOUD_ACCESS_KEY_SECRET
Caicloud aliyun account information, required to access aliyun dns, when `DOMAIN_NAME_IN_DNS == YES`.
DELETE_INSTANCE_FLAG
Determine whether to delete aliyun instances when kube-down.
Default value is `YES` (valid value: `YES/NO`).
REPORT_KUBE_STATUS
Default value is `N` (valid value: `Y/N`).
EXECUTOR_HOST_NAME
EXECUTION_ID
To indicate if the execution status needs to be reported back to caicloud executor.
NTPDATE_SYNC_TIME
Determine whether to sync time with ntpdate tool.
Default value is `NO` (valid value: `YES/NO`).
CLUSTER_NAME
If defined, we will use it as the security_group_name, master_name_prefix and node_name_prefix (in caicloud-aliyun/group_vars/all.yml). And it's no need to set MASTER_NAME_PREFIX and NODE_NAME_PREFIX.
MASTER_NAME_PREFIX
For aliyun instances hostname and the option --hostname-override on masters. It will be ignored if CLUSTER_NAME is set.
Default value is "kube-master-".
NODE_NAME_PREFIX
For aliyun instances hostname and the option --hostname-override on nodes. It will be ignored if CLUSTER_NAME is set.
Default value is "kube-node-".
```

## Change aliyun instances deployment configurations

We can change the default configurations of the aliyun instances by environment variables. If not seting these environment variables, It will use the default values. For details, please refer to [README-ALIYUN-INSTANCE](README-ALIYUN-INSTANCE.md).

Naming rules of aliyun instances environment variables:
```
CAICLOUD_ALIYUN_CFG_NUMBER_XX_YY
CAICLOUD_ALIYUN_CFG_STRING_XX_YY
```

`CAICLOUD_ALIYUN_CFG_NUMBER_/STRING_` is the prefix, `NUMBER` means its value is a number, `STRING` means its value is a string, and `XX_YY` is the variable name in uppercase.

For example, default value of `security_group_name` variable is `"kube-default"`, if we want to change the default value to `"dev-1"`, we should set the `CAICLOUD_ALIYUN_CFG_STRING_SECURITY_GROUP_NAME` environment variable:
```
# Recommended for each cluster to set up a security group
export CAICLOUD_ALIYUN_CFG_STRING_SECURITY_GROUP_NAME="dev-1"
```

## Change kubernetes cluster configurations

We can change the default configurations of the kubernetes cluster by environment variables. If not seting these environment variables, It will use the default values. For details, please refer to [README-ALIYUN-INSTANCE](../caicloud-ansible/README-ANSIBLE.md).

Naming rules of kubernetes cluster environment variables:
```
CAICLOUD_K8S_CFG_NUMBER_XX_YY
CAICLOUD_K8S_CFG_STRING_XX_YY
```

`CAICLOUD_K8S_CFG_NUMBER/STRING` is the prefix, `NUMBER` means its value is a number, `STRING` means its value is a string, and `XX_YY` is the variable name in uppercase.

For example, default value of `host_provider` variable is `"vagrant"`, if we want to change the default value to `"aliyun"`, we should set the `CAICLOUD_K8S_CFG_STRING_HOST_PROVIDER` environment variable:
```
export CAICLOUD_K8S_CFG_STRING_HOST_PROVIDER="aliyun"
```

## Bring up kubernete cluster on aliyun instances

Now, to bring up kubernete cluster, simply run:
```
KUBERNETES_PROVIDER=caicloud-aliyun ./cluster/kube-up.sh
```

## Bring down kubernetes cluster on aliyun instances

```
KUBERNETES_PROVIDER=caicloud-aliyun ./cluster/kube-down.sh
```

**Note:**

Aliyun instances will not be stopped and deleted after bringing down kubernetes cluster by default. If we also want to delete aliyun instances, please add `CAICLOUD_ALIYUN_CFG_STRING_DELETE_INSTANCE_FLAG="YES"`:

```
export CAICLOUD_ALIYUN_CFG_STRING_DELETE_INSTANCE_FLAG="YES"
KUBERNETES_PROVIDER=caicloud-aliyun ./cluster/kube-down.sh
```
Loading

0 comments on commit 30259bc

Please sign in to comment.