AWS Kubernetes

Objective


Learn how to set up an EC2 machine on AWS.


Steps


  1. Create an AWS account
  2. Create a new EC2 instance
    1. Specify which image to use
    2. Create & Download a certificate
    3. Create and associate an IP address
  3. Connect to the Machine using the AWS certificate
  4. Download the pre-requisites, the installer & run the Installer pre script on Amazon EC2



Step 1: Create an AWS account


  • Begin by Creating an AWS account →  Click Here.
    • Follow the steps of the AWS wizard



Step 2: Create a new EC2 Instance


  • Under the Services dropdown list pick EC2 then click on Launch Instance.
  • Specify Community AMIs from the left side bar menu, then pick ubuntu.
  • Pick the instance's Image
    1. Select ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-20170721
    2. Choose an instance type
      1. t2.medium to deploy SOAJS
      2. t2.large to deploy SOAJS with Analytics
    3. In step 6 Configure security groups, add 5 rules:
      1. Type: Custom TCP, Port Range: 22, Source: 0.0.0.0/0
      2. Type: Custom TCP, Port Range: 30080, Source: 0.0.0.0/0
      3. Type: Custom TCP, Port Range: 6443, Source: 0.0.0.0/0
      4. Type: Custom TCP, Port Range: 32017, Source: 0.0.0.0/0
  • Click Review and Launch so that the new instance starts.
  • Create & Download a Certificate
    1. From the left sidebar click on Key Pairs under NETWORK & SECURITY
    2. Create a new Key Pair and give it a name
    3. AWS will ask you to download and save the certificate
  • Create and Associate an IP address
    1. In the left menu click on Elastic IPs under NETWORK & SECURITY
    2. Click on Allocate new address 
    3. Link it to the machine instance created
Choose an Image for your Instance

Update Firewall Rules

Choose Instance Resource Flavor
Instance Options Menu



Step 3: Connect to the Machine on your Local Machine


Add the downloaded certificate my-key-pair.pem file of Step 2 to your local .ssh folder: 

Connect to the Machine
# copy certificate to your ssh folder
> mv my-key-pair.pem ~/.ssh/my-key-pair.pem
> cd ~/.ssh/
> chmod 400 my-key-pair.pem

# connect to the machine using certificate
> ssh -i my-key-pair.pem ubuntu@machine-ip-address



Step 4: Download the pre-requisites, the installer & run the Installer pre script on Amazon EC2


Once you SSH to the machine, you can download and run the installer pre installation script to get all the dependencies so that cloud deployment works.

Prepare the machine

Download & Run SOAJS Installer pre scripts
# download update apt-get, download nodejs-legacy, npm and zip
> sudo su
> apt-get update && apt install nodejs-legacy npm 

# download installer 
> mkdir -p /opt/soajs/node_modules 
> cd /opt/soajs/node_modules 
> sudo npm install soajs.installer 

# run installer pre script
> cd soajs.installer/scripts/pre 
> sudo /opt/soajs/node_modules/soajs.installer/scripts/pre/kubernetes-linux.sh <%YOUR_CUSTOM_DOMAIN%>

# By default, your cluster will not schedule pods on the master for security reasons.
# If you want to be able to schedule pods on the master, e.g. for a single-machine Kubernetes cluster for development, run
> kubectl taint nodes --all node-role.kubernetes.io/master:NoSchedule-

Grab the kubernetes Secret

Grab the kubernetes secret token by running the below command

Grab the Kubernetes Secret Token
# get kubernetes secrets
> kubectl describe secrets

# output
Name:		default-token-jc5fg
Namespace:	default
Labels:		<none>
Annotations:	kubernetes.io/service-account.name=default
		kubernetes.io/service-account.uid=50edbe21-8288-11e7-b935-bc764e2011e4

Type:	kubernetes.io/service-account-token

Data
====
ca.crt:		1025 bytes
namespace:	7 bytes
token:		eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6ImRlZmF1bHQtdG9rZW4tamM1ZmciLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGVmYXVsdCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjUwZWRiZTIxLTgyODgtMTFlNy1iOTM1LWJjNzY0ZTIwMTFlNCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0OmRlZmF1bHQifQ.0FtEvs9YLo9EZkVE9rYewEM6DdD4HWZMeuMBwznFEV6ZEjRSIv-yb21iCRSJTvUiSs1aiOQKl501Z7oVEq3RRbc2E3obR9CuvoUlYbzKTRwTT3ZeSNDJ--2ahlPCpE1WS0S_sfxMnS_eiafdY37wSzydD4baamQxX7ZgFy-kCyKc72ipXamXnH3ev2yxvSIjEuXeCT5XVDOyyghRp5OJAgcIzsKDPkkeDDnrvkSFGMYaW1Rrez7IV0VbwZCTccaQuyjhQbR8-zSMsJboRSud8BZOxrVAGKkiuWStL7isvp83zlqqI7yMj5SDjZiXcvCR4ijH0-j8FbI3e4LQipdb5w