Skip to content
This repository was archived by the owner on Oct 31, 2019. It is now read-only.

Commit 13915c2

Browse files
authored
Merge pull request #47 from oracle/jlamillan/private_cluster_support
Jlamillan/private cluster support
2 parents cbd8a76 + aa736e8 commit 13915c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1497
-1010
lines changed

README.md

Lines changed: 57 additions & 307 deletions
Large diffs are not rendered by default.

docs/cluster-access.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Accessing the Cluster
2+
3+
## Access the cluster using kubectl, continuous build pipelines, or other clients
4+
5+
If you've chosen to configure a _public_ Load Balancer for your Kubernetes Master(s) (i.e. `control_plane_subnet_access=public` or
6+
`control_plane_subnet_access=private` _and_ `k8s_master_lb_access=public`), you can interact with your cluster using kubectl, continuous build
7+
pipelines, or any other client over the Internet. A working kubeconfig can be found in the ./generated folder or generated on the fly using the `kubeconfig` Terraform output variable.
8+
9+
```bash
10+
# warning: 0.0.0.0/0 is wide open. Consider limiting HTTPs ingress to smaller set of IPs.
11+
$ terraform plan -var master_https_ingress=0.0.0.0/0
12+
$ terraform apply -var master_https_ingress=0.0.0.0/0
13+
# consider closing access off again using terraform apply -var master_https_ingress=10.0.0.0/16
14+
```
15+
16+
```bash
17+
$ export KUBECONFIG=`pwd`/generated/kubeconfig
18+
$ kubectl cluster-info
19+
$ kubectl get nodes
20+
```
21+
22+
If you've chosen to configure a strictly _private_ cluster (i.e. `control_plane_subnet_access=private` _and_ `k8s_master_lb_access=private`),
23+
access to the cluster will be limited to the NAT instance(s) similar to how you would use a bastion host e.g.
24+
25+
```bash
26+
$ terraform plan -var public_subnet_ssh_ingress=0.0.0.0/0
27+
$ terraform apply -var public_subnet_ssh_ingress=0.0.0.0/0
28+
$ terraform output ssh_private_key > generated/instances_id_rsa
29+
$ chmod 600 generated/instances_id_rsa
30+
$ scp -i generated/instances_id_rsa generated/instances_id_rsa opc@NAT_INSTANCE_PUBLIC_IP:/home/opc/
31+
$ ssh -i generated/instances_id_rsa opc@NAT_INSTANCE_PUBLIC_IP
32+
nat$ ssh -i /home/opc/instances_id_rsa opc@K8SMASTER_INSTANCE_PRIVATE_IP
33+
master$ kubectl cluster-info
34+
master$ kubectl get nodes
35+
```
36+
37+
Note, for easier access, consider setting up an SSH tunnel between your local host and a NAT instance.
38+
39+
## Access the cluster using Kubernetes Dashboard
40+
41+
Assuming `kubectl` has access to the Kubernetes Master Load Balancer, you can use `kubectl proxy` to access the
42+
Dashboard:
43+
44+
```
45+
kubectl proxy &
46+
open http://localhost:8001/ui
47+
```
48+
49+
## SSH into OCI Instances
50+
51+
If you've chosen to launch your control plane instance in _public_ subnets (i.e. `control_plane_subnet_access=public`), you can open
52+
access SSH access to your master nodes by adding the following to your `terraform.tfvars` file:
53+
54+
```bash
55+
# warning: 0.0.0.0/0 is wide open. remember to undo this.
56+
etcd_ssh_ingress = "0.0.0.0/0"
57+
master_ssh_ingress = "0.0.0.0/0"
58+
worker_ssh_ingress = "0.0.0.0/0"
59+
```
60+
61+
```bash
62+
# Create local SSH private key file logging into OCI instances
63+
$ terraform output ssh_private_key > generated/instances_id_rsa
64+
# Retrieve public IP for etcd nodes
65+
$ terraform output etcd_public_ips
66+
# Log in as user opc to the OEL OS
67+
$ ssh -i `pwd`/generated/instances_id_rsa opc@ETCD_INSTANCE_PUBLIC_IP
68+
# Retrieve public IP for k8s masters
69+
$ terraform output master_public_ips
70+
$ ssh -i `pwd`/generated/instances_id_rsa opc@K8SMASTER_INSTANCE_PUBLIC_IP
71+
# Retrieve public IP for k8s workers
72+
$ terraform output worker_public_ips
73+
$ ssh -i `pwd`/generated/instances_id_rsa opc@K8SWORKER_INSTANCE_PUBLIC_IP
74+
```
75+
76+
If you've chosen to launch your control plane instance in _private_ subnets (i.e. `control_plane_subnet_access=private`), you'll
77+
need to first SSH into a NAT instance, then to a worker, master, or etcd node:
78+
79+
```bash
80+
$ terraform plan -var public_subnet_ssh_ingress=0.0.0.0/0
81+
$ terraform apply -var public_subnet_ssh_ingress=0.0.0.0/0
82+
$ terraform output ssh_private_key > generated/instances_id_rsa
83+
$ chmod 600 generated/instances_id_rsa
84+
$ terraform output nat_instance_public_ips
85+
$ scp -i generated/instances_id_rsa generated/instances_id_rsa opc@NAT_INSTANCE_PUBLIC_IP:/home/opc/
86+
$ ssh -i generated/instances_id_rsa opc@NAT_INSTANCE_PUBLIC_IP
87+
nat$ ssh -i /home/opc/instances_id_rsa opc@PRIVATE_IP
88+
```

docs/examples.md

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
# Example Operations
2+
3+
## Deploying a new cluster using terraform apply
4+
5+
Override any of the above input variables in your terraform.vars and run the plan and apply commands:
6+
7+
```bash
8+
# verify what will change
9+
$ terraform plan
10+
11+
# scale workers
12+
$ terraform apply
13+
```
14+
15+
## Scaling k8s workers (in or out) using terraform apply
16+
17+
To scale workers in or out, adjust the `k8sWorkerAd1Count`, `k8sWorkerAd2Count`, or `k8sWorkerAd3Count` input
18+
variables in terraform.vars and run the plan and apply commands:
19+
20+
```bash
21+
# verify changes
22+
$ terraform plan
23+
24+
# scale workers (use -target=module.instances-k8sworker-adX to only target workers in a particular AD)
25+
$ terraform apply
26+
```
27+
28+
When scaling worker nodes _up_, you will need to wait for the node initialization to finish asynchronously before
29+
the new nodes will be seen with `kubectl get nodes`
30+
31+
When scaling worker nodes _down_, the instances/k8sworker module's user_data code will take care of running `kubectl drain` and `kubectl delete node` on the nodes being terminated.
32+
33+
## Scaling k8s masters (in or out) using terraform apply
34+
35+
To scale the masters in or out, adjust the `k8sMasterAd1Count`, `k8sMasterAd2Count`, or `k8sMasterAd3Count` input variables in terraform.vars and run the plan and apply commands:
36+
37+
```bash
38+
# verify changes
39+
$ terraform plan
40+
41+
# scale master nodes
42+
$ terraform apply
43+
```
44+
45+
Similar to the initial deployment, you will need to wait for the node initialization to finish asynchronously.
46+
47+
## Scaling etcd nodes (in or out) using terraform apply
48+
49+
Scaling the etcd nodes in or out after the initial deployment is not currently supported. Terminating all the nodes in the etcd cluster will result in data loss.
50+
51+
## Replacing worker nodes using terraform taint
52+
53+
We can use `terraform taint` to worker instances in a particular AD as "tainted", which will cause
54+
them to be destroyed and recreated on the next apply. This can be a useful strategy for reverting local changes or
55+
regenerating a misbehaving worker.
56+
57+
```bash
58+
# taint all workers in a particular AD
59+
terraform taint -module=instances-k8sworker-ad1 oci_core_instance.TFInstanceK8sWorker
60+
# optionally taint workers in AD2 and AD3 or do so in a subsequent apply
61+
# terraform taint -module=instances-k8sworker-ad2 oci_core_instance.TFInstanceK8sWorker
62+
# terraform taint -module=instances-k8sworker-ad3 oci_core_instance.TFInstanceK8sWorker
63+
64+
# preview changes
65+
$ terraform plan
66+
67+
# replace workers
68+
$ terraform apply
69+
```
70+
71+
## Replacing masters using terraform taint
72+
73+
We can also use `terraform taint` to master instances in a particular AD as "tainted", which will cause
74+
them to be destroyed and recreated on the next apply. This can be a useful strategy for reverting local
75+
changes or regenerating a misbehaving master.
76+
77+
```bash
78+
# taint all masters in a particular AD
79+
terraform taint -module=instances-k8smaster-ad1 oci_core_instance.TFInstanceK8sMaster
80+
# optionally taint masters in AD2 and AD3 or do so in a subsequent apply
81+
# terraform taint -module=instances-k8smaster-ad2 oci_core_instance.TFInstanceK8sMaster
82+
# terraform taint -module=instances-k8smaster-ad3 oci_core_instance.TFInstanceK8sMaster
83+
84+
# preview changes
85+
$ terraform plan
86+
87+
# replace workers
88+
$ terraform apply
89+
```
90+
91+
## Upgrading Kubernetes Version
92+
93+
There are a few ways of moving to a new version of Kubernetes in your cluster.
94+
95+
The easiest way to upgrade to a new Kubernetes version is to use the scripts to do a fresh cluster install using an updated `k8s_ver` inpput variable. The downside with this option is that the new cluster will not have your existing cluster state and deployments.
96+
97+
The other options involve using the `k8s_ver` input variable to _replace_ master and worker instances in your _existing_ cluster. We can replace master and worker instances in the cluster since Kubernetes masters and workers are stateless. This option can either be done all at once or incrementally.
98+
99+
#### Option 1: Do a clean install (easiest overall approach)
100+
101+
Set the `k8s_ver` and follow the original instructions in the [README](../README.md) do install a new cluster. The `label_prefix` variable is useful for installing multiple clusters in a compartment.
102+
103+
#### Option 2: Upgrade cluster all at once (easiest upgrade)
104+
105+
The example `terraform apply` command below will destroy then re-create all master and worker instances using as much parallelism as possible. It's the easiest and quickest upgrade scenario, but will result in some downtime for the workers and masters while they are being re-created. The single example `terraform apply` below will:
106+
107+
1. destroy all worker nodes
108+
2. destroy all master nodes
109+
3. destroy all master load-balancer backends that point to old master instances
110+
4. re-create master instances using Kubernetes 1.7.5
111+
5. re-create worker nodes using Kubernetes 1.7.5
112+
6. re-create master load-balancer backends to point to new master node instances
113+
114+
```bash
115+
# preview upgrade/replace
116+
$ terraform plan -var k8s_ver=1.7.5
117+
118+
# perform upgrade/replace
119+
$ terraform apply -var k8s_ver=1.7.5
120+
```
121+
122+
#### Option 3: Upgrade cluster instances incrementally (most complicated, most control over roll-out)
123+
124+
##### First, upgrade master nodes by AD
125+
126+
If you would rather update the cluster incrementally, we start by upgrading the master nodes in each AD. In this scenario, each `terraform apply` will:
127+
128+
1. destroy all master instances in a particular AD
129+
2. destroy all master load-balancer backends that point to deleted master instances
130+
3. re-create master instances in the AD using Kubernetes 1.7.5
131+
4. re-create master load-balancer backends to point to new master node instances
132+
133+
For example, here is the command to upgrade all the master instances in AD1:
134+
135+
```bash
136+
# preview upgrade of all masters and their LB backends in AD1
137+
$ terraform plan -var k8s_ver=1.7.5 -target=module.instances-k8smaster-ad1 -target=module.k8smaster-public-lb
138+
139+
# perform upgrade/replace masters
140+
$ terraform apply -var k8s_ver=1.7.5 -target=module.instances-k8smaster-ad1 -target=module.k8smaster-public-lb
141+
```
142+
143+
Be sure to repeat this command for each AD you have masters on.
144+
145+
##### Next, upgrade worker nodes by AD
146+
147+
After upgrading all the master nodes, we upgrade the worker nodes in each AD. Each `terraform apply` will:
148+
149+
1. drain all worker nodes in a particular AD to your nodes in AD2 and AD3
150+
2. destroy all worker nodes in a particular AD
151+
3. re-create worker nodes in a particular AD using Kubernetes 1.7.5
152+
153+
For example, here is the command to upgrade the master instances in AD1:
154+
155+
```bash
156+
# preview upgrade of all workers in a particular AD to K8s
157+
$ terraform plan -var k8s_ver=1.7.5 -target=module.instances-k8sworker-ad1
158+
159+
# perform upgrade/replace workers
160+
$ terraform apply -var k8s_ver=1.7.5 -target=module.instances-k8sworker-ad1
161+
```
162+
163+
Like before, repeat `terraform apply` on each AD you have workers on. Note that if you have more than one worker in an AD, you can upgrade worker nodes individually using the subscript operator e.g.
164+
165+
```bash
166+
# preview upgrade of a single worker in a particular AD to K8s 1.7.5
167+
$ terraform plan -var k8s_ver=1.7.5 -target=module.instances-k8smaster-ad1.oci_core_instance.TFInstanceK8sMaster[1]
168+
169+
# perform upgrade/replace of worker
170+
$ terraform apply -var k8s_ver=1.7.5 -target=module.instances-k8sworker-ad1
171+
```
172+
173+
## Replacing etcd cluster members using terraform taint
174+
175+
Replacing etcd cluster members after the initial deployment is not currently supported.
176+
177+
## Deleting a cluster using terraform destroy
178+
179+
```bash
180+
$ terraform destroy
181+
```

docs/images/arch.jpg

-6.6 KB
Loading
153 KB
Loading
151 KB
Loading
216 KB
Loading
104 KB
Loading

0 commit comments

Comments
 (0)