2015-07-12 04:04:52 +00:00
<!-- BEGIN MUNGE: UNVERSIONED_WARNING -->
<!-- BEGIN STRIP_FOR_RELEASE -->
2015-07-16 17:02:26 +00: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">
< h2 > PLEASE NOTE: This document applies to the HEAD of the source tree< / h2 >
If you are using a released version of Kubernetes, you should
refer to the docs that go with that version.
< 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/aws-coreos.md ).
Documentation for other releases can be found at
[releases.k8s.io ](http://releases.k8s.io ).
< / strong >
--
2015-07-13 22:15:35 +00:00
2015-07-12 04:04:52 +00:00
<!-- END STRIP_FOR_RELEASE -->
<!-- END MUNGE: UNVERSIONED_WARNING -->
2015-07-17 22:35:41 +00:00
2015-05-14 19:24:03 +00:00
# Getting started on Amazon EC2 with CoreOS
2014-11-22 00:50:13 +00:00
2015-05-14 19:24:03 +00:00
The example below creates an elastic Kubernetes cluster with a custom number of worker nodes and a master.
2014-11-22 00:50:13 +00:00
2015-05-14 19:24:03 +00:00
**Warning:** contrary to the [supported procedure ](aws.md ), the examples below provision Kubernetes with an insecure API server (plain HTTP,
no security tokens, no basic auth). For demonstration purposes only.
2014-11-10 21:35:57 +00:00
## Highlights
2015-05-14 19:24:03 +00:00
* Cluster bootstrapping using [cloud-config ](https://coreos.com/docs/cluster-management/setup/cloudinit-cloud-config/ )
2014-11-10 21:35:57 +00:00
* Cross container networking with [flannel ](https://github.com/coreos/flannel#flannel )
* Auto worker registration with [kube-register ](https://github.com/kelseyhightower/kube-register#kube-register )
2015-07-16 13:54:38 +00:00
* Kubernetes v0.19.3 [official binaries ](https://github.com/GoogleCloudPlatform/kubernetes/releases/tag/v0.19.3 )
2014-11-10 21:35:57 +00:00
## Prerequisites
* [aws CLI ](http://aws.amazon.com/cli )
2015-05-14 19:24:03 +00:00
* [CoreOS image for AWS ](https://coreos.com/docs/running-coreos/cloud-providers/ec2/ )
2015-07-14 23:16:50 +00:00
* [kubectl CLI ](aws/kubectl.md ) ([installation](aws.md#command-line-administration-tool-kubectl))
2014-11-10 21:35:57 +00:00
## Starting a Cluster
2015-05-14 19:24:03 +00:00
### CloudFormation
2014-11-10 21:35:57 +00:00
2015-05-14 19:24:03 +00:00
The [cloudformation-template.json ](aws/cloudformation-template.json ) can be used to bootstrap a Kubernetes cluster with a single command:
2014-11-10 21:35:57 +00:00
2015-05-14 19:24:03 +00:00
```bash
2014-11-10 21:35:57 +00:00
aws cloudformation create-stack --stack-name kubernetes --region us-west-2 \
--template-body file://aws/cloudformation-template.json \
2015-05-14 19:24:03 +00:00
--parameters ParameterKey=KeyPair,ParameterValue=< keypair > \
2015-06-06 16:51:40 +00:00
ParameterKey=ClusterSize,ParameterValue=< cluster_size > \
ParameterKey=VpcId,ParameterValue=< vpc_id > \
ParameterKey=SubnetId,ParameterValue=< subnet_id > \
ParameterKey=SubnetAZ,ParameterValue=< subnet_az >
2014-11-10 21:35:57 +00:00
```
It will take a few minutes for the entire stack to come up. You can monitor the stack progress with the following command:
2015-05-14 19:24:03 +00:00
```bash
2014-11-10 21:35:57 +00:00
aws cloudformation describe-stack-events --stack-name kubernetes
```
2015-05-14 19:24:03 +00:00
Record the Kubernetes Master IP address:
2014-11-10 21:35:57 +00:00
2015-05-14 19:24:03 +00:00
```bash
2014-11-10 21:35:57 +00:00
aws cloudformation describe-stacks --stack-name kubernetes
```
2015-02-05 07:06:03 +00:00
[Skip to kubectl client configuration ](#configure-the-kubectl-ssh-tunnel )
2014-11-10 21:35:57 +00:00
2015-05-14 19:24:03 +00:00
### AWS CLI
2014-11-10 21:35:57 +00:00
2015-01-16 11:25:10 +00:00
The following commands shall use the latest CoreOS alpha AMI for the `us-west-2` region. For a list of different regions and corresponding AMI IDs see the [CoreOS EC2 cloud provider documentation ](https://coreos.com/docs/running-coreos/cloud-providers/ec2/#choosing-a-channel ).
2014-11-10 21:35:57 +00:00
#### Create the Kubernetes Security Group
2015-05-14 19:24:03 +00:00
```bash
2014-11-10 21:35:57 +00:00
aws ec2 create-security-group --group-name kubernetes --description "Kubernetes Security Group"
aws ec2 authorize-security-group-ingress --group-name kubernetes --protocol tcp --port 22 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-name kubernetes --protocol tcp --port 80 --cidr 0.0.0.0/0
aws ec2 authorize-security-group-ingress --group-name kubernetes --source-security-group-name kubernetes
```
#### Save the master and node cloud-configs
* [master.yaml ](aws/cloud-configs/master.yaml )
* [node.yaml ](aws/cloud-configs/node.yaml )
#### Launch the master
2015-05-14 19:24:03 +00:00
*Attention:* replace `<ami_image_id>` below for a [suitable version of CoreOS image for AWS ](https://coreos.com/docs/running-coreos/cloud-providers/ec2/ ).
2015-01-16 11:25:10 +00:00
2015-05-14 19:24:03 +00:00
```bash
2015-01-21 23:00:16 +00:00
aws ec2 run-instances --image-id < ami_image_id > --key-name < keypair > \
2014-11-10 21:35:57 +00:00
--region us-west-2 --security-groups kubernetes --instance-type m3.medium \
--user-data file://master.yaml
```
2015-05-14 19:24:03 +00:00
Record the `InstanceId` for the master.
2014-11-10 21:35:57 +00:00
Gather the public and private IPs for the master node:
2015-05-14 19:24:03 +00:00
```bash
2014-11-10 21:35:57 +00:00
aws ec2 describe-instances --instance-id < instance-id >
```
2015-07-20 16:40:32 +00:00
```json
2014-11-10 21:35:57 +00:00
{
"Reservations": [
{
"Instances": [
{
"PublicDnsName": "ec2-54-68-97-117.us-west-2.compute.amazonaws.com",
"RootDeviceType": "ebs",
"State": {
"Code": 16,
"Name": "running"
},
"PublicIpAddress": "54.68.97.117",
"PrivateIpAddress": "172.31.9.9",
```
#### Update the node.yaml cloud-config
Edit `node.yaml` and replace all instances of `<master-private-ip>` with the **private** IP address of the master node.
### Launch 3 worker nodes
2015-05-14 19:24:03 +00:00
*Attention:* Replace `<ami_image_id>` below for a [suitable version of CoreOS image for AWS ](https://coreos.com/docs/running-coreos/cloud-providers/ec2/#choosing-a-channel ).
2015-01-16 11:25:10 +00:00
2015-05-14 19:24:03 +00:00
```bash
2015-01-16 11:25:10 +00:00
aws ec2 run-instances --count 3 --image-id < ami_image_id > --key-name < keypair > \
2014-11-10 21:35:57 +00:00
--region us-west-2 --security-groups kubernetes --instance-type m3.medium \
--user-data file://node.yaml
```
### Add additional worker nodes
2015-05-14 19:24:03 +00:00
*Attention:* replace `<ami_image_id>` below for a [suitable version of CoreOS image for AWS ](https://coreos.com/docs/running-coreos/cloud-providers/ec2/#choosing-a-channel ).
2015-01-16 11:25:10 +00:00
2015-05-14 19:24:03 +00:00
```bash
2015-01-16 11:25:10 +00:00
aws ec2 run-instances --count 1 --image-id < ami_image_id > --key-name < keypair > \
2014-11-10 21:35:57 +00:00
--region us-west-2 --security-groups kubernetes --instance-type m3.medium \
--user-data file://node.yaml
```
2015-02-05 07:06:03 +00:00
### Configure the kubectl SSH tunnel
2014-11-10 21:35:57 +00:00
2015-02-05 07:06:03 +00:00
This command enables secure communication between the kubectl client and the Kubernetes API.
2014-11-10 21:35:57 +00:00
2015-05-14 19:24:03 +00:00
```bash
2014-11-10 21:35:57 +00:00
ssh -f -nNT -L 8080:127.0.0.1:8080 core@< master-public-ip >
```
### Listing worker nodes
Once the worker instances have fully booted, they will be automatically registered with the Kubernetes API server by the kube-register service running on the master node. It may take a few mins.
2015-05-14 19:24:03 +00:00
```bash
2015-02-05 07:06:03 +00:00
kubectl get nodes
2014-11-10 21:35:57 +00:00
```
## Starting a simple pod
Create a pod manifest: `pod.json`
2015-05-14 19:24:03 +00:00
```json
2014-11-10 21:35:57 +00:00
{
2015-06-05 19:47:15 +00:00
"apiVersion": "v1",
2014-11-10 21:35:57 +00:00
"kind": "Pod",
2015-05-14 19:24:03 +00:00
"metadata": {
"name": "hello",
"labels": {
"name": "hello",
"environment": "testing"
2014-11-10 21:35:57 +00:00
}
},
2015-05-14 19:24:03 +00:00
"spec": {
"containers": [{
"name": "hello",
"image": "quay.io/kelseyhightower/hello",
"ports": [{
"containerPort": 80,
"hostPort": 80
}]
}]
2014-11-10 21:35:57 +00:00
}
}
```
2015-02-05 07:06:03 +00:00
### Create the pod using the kubectl command line tool
2014-11-10 21:35:57 +00:00
2015-05-14 19:24:03 +00:00
```bash
2015-07-16 00:20:39 +00:00
kubectl create -f ./pod.json
2014-11-10 21:35:57 +00:00
```
### Testing
2015-05-14 19:24:03 +00:00
```bash
2015-02-05 07:06:03 +00:00
kubectl get pods
2014-11-10 21:35:57 +00:00
```
2015-05-14 19:24:03 +00:00
Record the **Host** of the pod, which should be the private IP address.
2014-11-10 21:35:57 +00:00
2015-07-24 21:52:18 +00:00
Gather the public IP address for the worker node.
2014-11-10 21:35:57 +00:00
2015-05-14 19:24:03 +00:00
```bash
2014-11-10 21:35:57 +00:00
aws ec2 describe-instances --filters 'Name=private-ip-address,Values=< host > '
```
2015-07-20 16:40:32 +00:00
```json
2014-11-10 21:35:57 +00:00
{
"Reservations": [
{
"Instances": [
{
"PublicDnsName": "ec2-54-68-97-117.us-west-2.compute.amazonaws.com",
"RootDeviceType": "ebs",
"State": {
"Code": 16,
"Name": "running"
},
"PublicIpAddress": "54.68.97.117",
```
Visit the public IP address in your browser to view the running pod.
### Delete the pod
2015-05-14 19:24:03 +00:00
```bash
2015-02-05 07:06:03 +00:00
kubectl delete pods hello
2014-11-10 21:35:57 +00:00
```
2015-05-14 22:12:45 +00:00
2015-07-14 00:13:09 +00:00
<!-- BEGIN MUNGE: GENERATED_ANALYTICS -->
2015-05-14 22:12:45 +00:00
[![Analytics ](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/docs/getting-started-guides/aws-coreos.md?pixel )]()
2015-07-14 00:13:09 +00:00
<!-- END MUNGE: GENERATED_ANALYTICS -->