Skip to content

Commit 471d18d

Browse files
committed
Move kops section to Appendix
1 parent fa3057f commit 471d18d

File tree

4 files changed

+144
-3
lines changed

4 files changed

+144
-3
lines changed

01-path-basics/101-start-here/readme.adoc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Once your Cloud9 is ready, download the build script and install in your IDE. Th
6969
- kubectl _(the Kubernetes CLI, which we'll cover in great detail later in the workshop)_
7070
- heptio/authenticator _(for authentication to the EKS cluster)_
7171
- updates/configures the AWS CLI and stores necessary environment variables in bash_profile
72+
- kops _(Kubernetes Operations, which we'll also cover in detail later)_
7273
- creates an SSH key
7374
- clone the workshop repository into Cloud9
7475

@@ -106,7 +107,7 @@ You are now ready to continue on with the workshop!
106107
|link:../../operations-path.adoc[Go to Operations Index]
107108
|=====
108109

109-
The next step is link:../102-your-first-cluster[to create a Kubernetes cluster using EKS].
110+
The next step is link:../102-your-first-cluster[to create a Kubernetes cluster].
110111

111112

112113
== Workshop Cleanup
@@ -116,6 +117,8 @@ Once you have finished with the workshop, please don't forget to spin down your
116117

117118
Ensure that you have deleted all services, etc from the `default` namespace before proceeding.
118119

120+
=== Using EKS
121+
119122
==== Delete EKS worker nodeds
120123

121124
Go to CloudFormation console, right click template with name 'k8s-workshop-worker-nodes' and select 'Delete Stack'
@@ -132,7 +135,21 @@ Delete EKS cluster
132135

133136
Wait until all resources are deleted by kops
134137

135-
==== Delete Cloud9 Envionment
138+
=== Using kops
139+
140+
==== Delete Kubernetes cluster resources
141+
142+
In your Cloud9 IDE, check if there are any running kubernetes cluster
143+
144+
$ kops get cluster
145+
146+
Delete kubernetes cluster
147+
148+
$ kops delete cluster example.cluster.k8s.local --yes
149+
150+
Wait until all resources are deleted by kops
151+
152+
=== Delete Cloud9 Envionment
136153

137154
Go to CloudFormation console, right click template with name 'k8s-workshop' and select 'Delete Stack'
138155

01-path-basics/101-start-here/scripts/lab-ide-build.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ chmod +x kubectl && sudo mv kubectl /usr/local/bin/
2525
curl -o heptio-authenticator-aws https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/bin/linux/amd64/heptio-authenticator-aws
2626
chmod +x ./heptio-authenticator-aws && sudo mv heptio-authenticator-aws /usr/local/bin/
2727

28+
# Install kops
29+
curl -LO https://github.com/kubernetes/kops/releases/download/$(curl -s https://api.github.com/repos/kubernetes/kops/releases/latest | grep tag_name | cut -d '"' -f 4)/kops-linux-amd64
30+
chmod +x kops-linux-amd64
31+
sudo mv kops-linux-amd64 /usr/local/bin/kops
32+
2833
# Configure AWS CLI
2934
availability_zone=$(curl http://169.254.169.254/latest/meta-data/placement/availability-zone)
3035
export AWS_DEFAULT_REGION=${availability_zone%?}
@@ -47,7 +52,6 @@ export EKS_SECURITY_GROUPS=$(aws cloudformation describe-stacks --stack-name $AW
4752
export EKS_SERVICE_ROLE=$(aws cloudformation describe-stacks --stack-name $AWS_MASTER_STACK | jq -r '.Stacks[0].Outputs[]|select(.OutputKey=="EksServiceRoleArn")|.OutputValue')
4853

4954
# Persist lab variables
50-
echo "export PATH=$HOME/go/bin:$PATH" >> ~/.bashrc
5155
echo "AWS_AVAILABILITY_ZONES=$AWS_AVAILABILITY_ZONES" >> ~/.bash_profile
5256
echo "KOPS_STATE_STORE=$KOPS_STATE_STORE" >> ~/.bash_profile
5357
echo "export AWS_AVAILABILITY_ZONES KOPS_STATE_STORE" >> ~/.bash_profile

01-path-basics/102-your-first-cluster/readme.adoc

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,120 @@ The next step is link:../103-kubernetes-concepts[to learn about basic Kubernetes
140140

141141
The sections below provide information on other capabilities of Kubernetes clusters.
142142
You are welcome to read and refer to them should you need to use those capabilities.
143+
144+
== Alternative: Create a Kubernetes Cluster with kops
145+
146+
This section will walk you through how to install a Kubernetes cluster on AWS using kops.
147+
148+
https://github.com/kubernetes/kops[kops, window="_blank"], short for Kubernetes Operations, is a set of tools for installing, operating, and deleting Kubernetes clusters. kops can also perform rolling upgrades from older versions of Kubernetes to newer ones, and manage the cluster add-ons.
149+
150+
kops can be used to create a highly available cluster, with multiple master and worker nodes spread across multiple availability zones.
151+
The master and worker nodes within the cluster can use either DNS or the https://github.com/weaveworks/mesh[Weave Mesh, window="_blank"] *gossip* protocol for name resolution. For this workshop, we will use the gossip protocol. A gossip-based cluster is easier and quicker to setup, and does not require a domain, subdomain, or Route53 hosted zone to be registered. Instructions for creating a DNS-based cluster are provided as an appendix at the bottom of this page.
152+
153+
To create a cluster using the gossip protocol, simply use a cluster name with a suffix of `.k8s.local`. In the following steps, we will use `example.cluster.k8s.local` as a sample gossip cluster name. You may choose a different name as long as it ends with `.k8s.local`.
154+
155+
We show two examples of creating gossip-based clusters below. You can choose whether to create a single-master or multi-master cluster. Most workshop exercises will work on both types of cluster, however some modules require using a multi-master cluster _(to demonstrate rolling updates, for instance)._ If you aren't sure, please create a xref:multi-master[multi-master cluster].
156+
157+
=== Single-Master Cluster
158+
159+
By default, the `kops create cluster` command creates a single master node and two worker nodes in the specified zones.
160+
161+
Create a Kubernetes cluster using the following command. Run it in the "bash" terminal tab at the bottom of the Cloud9 IDE. This will create a cluster with a single master, multi-node and multi-az configuration:
162+
163+
$ kops create cluster \
164+
--name example.cluster.k8s.local \
165+
--zones $AWS_AVAILABILITY_ZONES \
166+
--yes
167+
168+
The `AWS_AVAILABILITY_ZONES` environment variable should have been set during the link:../101-start-here[Cloud9 Environment Setup].
169+
170+
The `create cluster` command only creates and stores the cluster config in the S3 bucket. Adding the `--yes` flag ensures that the cluster is immediately created as well.
171+
172+
Once the `kops create cluster` command is issued, it provisions the EC2 instances, sets up Auto Scaling Groups, IAM users, Security Groups, installs Kubernetes on each node, then configures the master and worker nodes. This process can take some time based upon the number of master and worker nodes.
173+
174+
Note: If your 'create cluster' fails with an error like:
175+
```
176+
error reading s3://example-kops-state-store/example.cluster.k8s.local/config: Unable to list AWS regions: NoCredentialProviders: no valid providers in chain
177+
caused by: EnvAccessKeyNotFound: failed to find credentials in the environment."
178+
```
179+
Please confirm the following environment variables are set before executing the 'create cluster' command:
180+
```
181+
echo $AWS_DEFAULT_PROFILE
182+
echo $KOPS_STATE_STORE
183+
echo $AWS_SDK_LOAD_CONFIG
184+
```
185+
If any of those environment variables are blank, please re-run the "Build Script" section of the link:../101-start-here[Cloud9 Environment Setup].
186+
187+
Wait for 5-8 minutes and then the cluster can be validated as shown:
188+
189+
```
190+
$ kops validate cluster
191+
Using cluster from kubectl context: example.cluster.k8s.local
192+
193+
Validating cluster example.cluster.k8s.local
194+
195+
INSTANCE GROUPS
196+
NAME ROLE MACHINETYPE MIN MAX SUBNETS
197+
master-eu-central-1a Master m3.medium 1 1 eu-central-1a
198+
nodes Node t2.medium 2 2 eu-central-1a,eu-central-1b
199+
200+
NODE STATUS
201+
NAME ROLE READY
202+
ip-172-20-57-94.ec2.internal master True
203+
ip-172-20-63-55.ec2.internal node True
204+
ip-172-20-75-78.ec2.internal node True
205+
206+
Your cluster example.cluster.k8s.local is ready
207+
```
208+
209+
anchor:multi-master[]
210+
211+
=== Multi-Master Cluster
212+
213+
The command below creates a cluster in a multi-master, multi-node, and multi-az configuration.
214+
Run it in the "bash" terminal tab at the bottom of the Cloud9 IDE.
215+
We can create and build the cluster in one step by passing the `--yes` flag.
216+
217+
$ kops create cluster \
218+
--name example.cluster.k8s.local \
219+
--master-count 3 \
220+
--node-count 5 \
221+
--zones $AWS_AVAILABILITY_ZONES \
222+
--yes
223+
224+
A multi-master cluster can be created by using the `--master-count` option and specifying the number of master nodes. An odd value is recommended. By default, the master nodes are spread across the AZs specified using the `--zones` option. Alternatively, you can use the `--master-zones` option to explicitly specify the zones for the master nodes.
225+
226+
The `--zones` option is also used to distribute the worker nodes. The number of workers is specified using the `--node-count` option.
227+
228+
It will take 5-8 minutes for the cluster to be created. Validate the cluster:
229+
230+
```
231+
$ kops validate cluster
232+
Using cluster from kubectl context: example.cluster.k8s.local
233+
234+
Validating cluster example.cluster.k8s.local
235+
236+
INSTANCE GROUPS
237+
NAME ROLE MACHINETYPE MIN MAX SUBNETS
238+
master-eu-central-1a Master m3.medium 1 1 eu-central-1a
239+
master-eu-central-1b Master m3.medium 1 1 eu-central-1b
240+
master-eu-central-1c Master c4.large 1 1 eu-central-1c
241+
nodes Node t2.medium 5 5 eu-central-1a,eu-central-1b,eu-central-1c
242+
243+
NODE STATUS
244+
NAME ROLE READY
245+
ip-172-20-101-97.ec2.internal node True
246+
ip-172-20-119-53.ec2.internal node True
247+
ip-172-20-124-138.ec2.internal master True
248+
ip-172-20-35-15.ec2.internal master True
249+
ip-172-20-63-104.ec2.internal node True
250+
ip-172-20-69-241.ec2.internal node True
251+
ip-172-20-84-65.ec2.internal node True
252+
ip-172-20-93-167.ec2.internal master True
253+
254+
Your cluster example.cluster.k8s.local is ready
255+
```
256+
257+
Note that all masters are spread across different AZs.
258+
259+
Your output may differ slightly from the one shown here based up on the type of cluster you created.

01-path-basics/103-kubernetes-concepts/readme.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Kubernetes as a platform has a number of abstractions that map to API objects. T
1616

1717
This chapter uses an EKS cluster with worker nodes as described link:../102-your-first-cluster[here].
1818

19+
[NOTE]
20+
This lab and future labs can be completed using the EKS cluster or the multi-master kops cluster. Some of the outputs may vary slightly if using the kops cluster.
21+
1922
All configuration files for this chapter are in the `01-path-basics/103-kubernetes-concepts/templates` directory.
2023
Please be sure to `cd` into that directory before running the commands below.
2124

0 commit comments

Comments
 (0)