Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add doc on how to provision kubernetes on aws #71

Merged
merged 1 commit into from
Oct 29, 2018

Conversation

liufuyang
Copy link
Contributor

Hi there,

I would like to try to add a doc on how to provision a k8s on AWS via EKS and Terraform code.

Do you think it would be a good idea to add a doc like this here?

And do you have any suggestion where to put the terraform code?
In this repo as well or somewhere else? I am thinking about using some of the terraform code from here:
/~https://github.com/wardviaene/terraform-course/tree/master/eks-demo
But not sure whether it will work out of the box or not.

Also I hope it is okay to open this work-in-progress PR, as I am in the hope someone else is trying the same and perhaps can help out with writing the doc as well :)

@CLAassistant
Copy link

CLAassistant commented Aug 31, 2018

CLA assistant check
All committers have signed the CLA.

@weekface weekface changed the title Add doc on how to provision kubernetes on aws [WIP] [WIP] Add doc on how to provision kubernetes on aws Aug 31, 2018
@gregwebs
Copy link
Contributor

Yes, we would like to have a AWS doc! I prefer using terraform. However, in our google tutorial, for the sake of fewer dependencies, we use cli commands, and we would likely tend to do the same for AWS (or maybe use cloudformation). But it would be good to also have a terraform alternative, so if you write your doc, that will help us figure out how to organize terraform documentation.

I actually made some terraform for this 2 months ago, but its basically just a copy of what was here at the time.

@liufuyang
Copy link
Contributor Author

liufuyang commented Aug 31, 2018

oh cool, thanks for the info. Definitely it will help. I will try compare those repos and see if I can make one that works for tidb. Hopefully they just work out of the box :D

@morgo
Copy link
Contributor

morgo commented Sep 15, 2018

Hi @liufuyang, your tutorial is looking good! I'm happy to test it out and provide feedback when you are ready.

@liufuyang
Copy link
Contributor Author

@morgo Thank you for the support. I am a bit busy these days, will try to find sometime to complete it and it would be very helpful if you could test it out as well :)

(Just a note to myself here: it seems AWS has just released some EKS optimised AMIs, might need to check out if they can be used for our cases. https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami.html)

@morgo
Copy link
Contributor

morgo commented Sep 17, 2018

@liufuyang Google has something similar: Container Optimized OS (cos).

It is a best practice to use a minimal OS so the surface area for vulnerabilities is lower. It should work just fine :-)

@liufuyang liufuyang changed the title [WIP] Add doc on how to provision kubernetes on aws Add doc on how to provision kubernetes on aws Sep 22, 2018
@liufuyang
Copy link
Contributor Author

@morgo @gregwebs Today I have successfully deployed tidb onto an AWS EKS cluster, and update my doc here, it still needs a bit of further polishing but now if you want to try out, you can try test it out. With terraform, it seems fairly simple to deploy a cluster onto AWS.

Let me know if you have any questions or ideas on improve this doc.

Copy link
Contributor

@morgo morgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing work - thank you so much!

Sorry for my delay in reviewing, I had a project I had to finish off before attempting this.


## Introduction

This tutorial is designed to be run locally with tools like [AWS Command Line Interface](https://aws.amazon.com/cli/) and [Terraform](https://www.terraform.io/). The Terraform code will ultilize a relatively new AWS service called [Amazon Elastic Container Service for Kubernetes (Amazon EKS)](https://aws.amazon.com/eks).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a suggestion: did you want to make it tailored for running on a stock Amazon Linux 2 AMI? That way you can include pastes for exact commands.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not exactly sure what do you mean here. I didn't tailor it for anything. I am simply trying to use AWS EKS service, and it seems the easiest solution is just to use the default AMI they suggest to use?
https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant: many people deploy on AWS with a Bastian host running Amazon Linux. You could simplify the instructions if instead of running locally (with instructions for both Mac OS X + Linux) you provide instructions to run on the Bastian host. In this way, it would be similar to the GKE tutorial with Cloud Shell always being Debian.

(This is independent of the OS the EKS deploy uses.)

belongs to. With more detailed permissions, you will have to be sure you also have
`AmazonEKSClusterPolicy` and `AmazonEKSServicePolicy` for this user.

Then generate a pair of access keys and keep them safe locally. Now we can continue about using Terraform to provision a Kubernetes on AWS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do chose to make it Amazon Linux 2 EC2 based - please also suggest assigning a role to an instance instead here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I am not that a guru of AWS IAM yet, mind if I ask why we need a role here? I think the worker instances are all managed by the EKS service, and this EKS services is started by a user who has AmazonEKSClusterPolicy and AmazonEKSServicePolicy .

Or if we have a role, I am not exactly sure how to configure the terraform code to use certain roles.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is about assigning a role to the Bastian/Cloud Shell. It is not required - just a suggestion to avoid saving credentials on the machine.


## A bit more about Terraform

Information about using Terraform with EKS can be found [here](https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"We will use Terraform templates to deploy EKS. Please install terraform using the steps described in the terraform manual. For example, on Linux:

wget https://releases.hashicorp.com/terraform/0.11.10/terraform_0.11.10_linux_amd64.zip
unzip terraform*
sudo mv terraform /usr/local/bin/

(Optional) You can confirm that Terraform is installed correctly by deploying the most simple infrastructure provision. From the Terraform manual:

.. paste example ..

In our next step, we will be deploying infrastructure based on the Terraform EKS tutorial.

the most simplest infrastructure provision (e.g [this example](https://www.terraform.io/intro/getting-started/build.html#configuration)) before you
continue.

## Launch a 3-node Kubernetes cluster
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should say "Install Terraform", since you do not launch a 3-node Kubernetes cluster until the next step.

For now we will follow the configs from the [last link](/~https://github.com/liufuyang/terraform-course/tree/master/eks-demo).
As it should be more easier and has more related info.

## Setting up AWS EKS (Hosted Kubernetes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be "Clone Tutorial Repo" (or similar) ?



### Destroy
At the end of the demo, please make sure all the resources created by Kubernetes are removed (LoadBalancers, Security groups), and issue:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this to the very end of the tutorial.


**Now you can switch back to the `tidb-operator` folder to follow the guide below.**

Then from this stage, you should be able to follow the [Tidb-Operator guide](/~https://github.com/pingcap/tidb-operator/blob/master/docs/google-kubernetes-tutorial.md) from section `Install Helm`, `Deploy TiDB Operator` and so on.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should include helm install steps here. They can be a direct paste:

curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
chmod 700 get_helm.sh && ./get_helm.sh

# clone repo
git clone /~https://github.com/pingcap/tidb-operator.git

If you already have helm installed, you can continue here:
```
kubectl create serviceaccount tiller --namespace kube-system &&
kubectl apply -f ./manifests/tiller-rbac.yaml &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either cd to tidb-operator in the commands:

cd tidb-operator
kubectl apply -f ./manifests/tiller-rbac.yaml

or type full command:

kubectl apply -f ./tidb-operator/manifests/tiller-rbac.yaml

FYI: The weird && is for Google Cloud Shell. The paste commands must be chained. You can remove it for AWS if you want.

Then from this stage, you should be able to follow the [Tidb-Operator guide](/~https://github.com/pingcap/tidb-operator/blob/master/docs/google-kubernetes-tutorial.md) from section `Install Helm`, `Deploy TiDB Operator` and so on.

### Deploy tidb-operator

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain what TIDB Operator does briefly.


Or just:
```
kubectl -n tidb port-forward demo-tidb-0 4000:4000 &>/tmp/port-forward.log &
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works!

@liufuyang
Copy link
Contributor Author

@morgo I have updated the doc based on your input, please take a look again :)

morgo
morgo previously approved these changes Oct 27, 2018
Copy link
Contributor

@morgo morgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A couple of small comments left in the document, but very good work!

### Deploy Kubernetes Dashboard

#### Step 1: Deploy the Dashboard

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add (optional) here too. If they do deploy on a bastian host, it will be harder to get the dashboard to work.

@liufuyang
Copy link
Contributor Author

liufuyang commented Oct 28, 2018

@gregwebs and @morgo, I squashed and rebased onto mater, plus a few final touches on the doc.

Copy link
Member

@tennix tennix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@morgo
Copy link
Contributor

morgo commented Oct 29, 2018

@liufuyang one more suggestion. Did you want to push the contents of terraform-course/eks-demo in this PR? That will simplify the repo cloning for users.

@QueenyJin QueenyJin self-requested a review October 29, 2018 04:10
@tennix
Copy link
Member

tennix commented Oct 29, 2018

I would suggest do it in another PR. I'm merging it now.

@tennix tennix merged commit 705f006 into pingcap:master Oct 29, 2018
@liufuyang liufuyang deleted the aws-eks-tidb branch October 29, 2018 22:27
@liufuyang
Copy link
Contributor Author

oh cool, thanks for merging it. I will try find time to create a new PR to move the terraform code here 😄

queenliuxx pushed a commit to queenliuxx/tidb-operator that referenced this pull request Dec 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants