Skip to content

Commit 5a4b11c

Browse files
authored
Update installation manifests and instructions (nginx#234)
1 parent 6043335 commit 5a4b11c

28 files changed

+424
-393
lines changed

docs/installation.md

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Installing the Ingress Controller
2+
3+
## Prerequisites
4+
5+
Make sure you have access to the Ingress controller image:
6+
7+
* For NGINX Ingress controller, use the image `nginxdemos/nginx-ingress` from [DockerHub](https://hub.docker.com/r/nginxdemos/nginx-ingress/).
8+
* For NGINX Plus Ingress controller, build your own image and push it to your private Docker registry by following the instructions from [here](../nginx-controller).
9+
10+
The installation manifests are located in the [install](../install) folder. In the steps below we assume that you will be running the commands from that folder.
11+
12+
## 1. Create a Namespace, a SA and the Default Secret.
13+
14+
1. Create a namespace and a service account for the Ingress controller:
15+
```
16+
kubectl apply -f common/ns-and-sa.yaml
17+
18+
```
19+
20+
1. Create a secret with a TLS certificate and a key for the default server in NGINX:
21+
```
22+
$ kubectl apply -f common/default-server-secret.yaml
23+
```
24+
25+
**Note**: The default server returns the Not Found page with the 404 status code for all requests for domains for which there are no Ingress rules defined. For testing purposes we include a self-signed certificate and key that we generated. However, we recommend that you use your own certificate and key.
26+
27+
1. *Optional*. Create a config map for customizing NGINX configuration (read more about customization [here](../examples/customization)):
28+
```
29+
$ kubectl apply -f common/nginx-config.yaml
30+
```
31+
32+
## 2. Configure RBAC
33+
34+
If RBAC is enabled in your cluster, create a cluster role and bind it to the service account, created in Step 1:
35+
```
36+
$ kubectl apply -f rbac/rbac.yaml
37+
```
38+
39+
**Note**: To perform this step you must be a cluster admin.
40+
41+
## 3. Deploy the Ingress Controller
42+
43+
We include two options for deploying the Ingress controller:
44+
* *Deployment*. Use a Deployment if you plan to dynamically change the number of Ingress controller replicas.
45+
* *DaemonSet*. Use a DaemonSet for deploying the Ingress controller on every node or a subset of nodes.
46+
47+
### 3.1 Create a Deployment
48+
49+
For NGINX, run:
50+
```
51+
$ kubectl apply -f deployment/nginx-ingress.yaml
52+
```
53+
54+
For NGINX Plus, run:
55+
```
56+
$ kubectl apply -f deployment/nginx-plus-ingress.yaml
57+
```
58+
59+
**Note**: Update the `nginx-plus-ingress.yaml` with the container image that you have built.
60+
61+
Kubernetes will create one Ingress controller pod.
62+
63+
64+
### 3.2 Create a DaemonSet
65+
66+
For NGINX, run:
67+
```
68+
$ kubectl apply -f daemon-set/nginx-ingress.yaml
69+
```
70+
71+
For NGINX Plus, run:
72+
```
73+
$ kubectl apply -f daemon-set/nginx-plus-ingress.yaml
74+
```
75+
76+
**Note**: Update the `nginx-plus-ingress.yaml` with the container image that you have built.
77+
78+
Kubernetes will create an Ingress controller pod on every node of the cluster. Read [this doc](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) to learn how to run the Ingress controller on a subset of nodes, instead of every node of the cluster.
79+
80+
### 3.3 Check that the Ingress Controller is Running
81+
82+
Run the following command to make sure that the Ingress controller pods are running:
83+
```
84+
$ kubectl get pods --namespace=nginx-ingress
85+
```
86+
87+
## 4. Get Access to the Ingress Controller
88+
89+
**If you created a daemonset**, ports 80 and 443 of the Ingress controller container are mapped to the same ports of the node where the container is running. To access the Ingress controller, use those ports and an IP address of any node of the cluster where the Ingress controller is running.
90+
91+
**If you created a deployment**, below are two options for accessing the Ingress controller pods.
92+
93+
### 4.1 Service with the Type NodePort
94+
95+
Create a service with the type *NodePort*:
96+
```
97+
$ kubectl create -f service/nodeport.yaml
98+
```
99+
Kubernetes will allocate two ports on every node of the cluster. To access the Ingress controller, use an IP address of any node of the cluster along with two allocated ports. Read more about the type NodePort [here](https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport).
100+
101+
### 4.2 Service with the Type LoadBalancer
102+
103+
Create a service with the type *LoadBalancer*. Kubernetes will allocate and configure a cloud load balancer for load balancing the Ingress controller pods.
104+
105+
Create a service using a manifest for your cloud provider:
106+
* For GCP or Azure, run:
107+
```
108+
$ kubectl apply -f service/loadbalancer.yaml
109+
```
110+
* For AWS, run:
111+
```
112+
$ kubectl apply -f service/loadbalancer-aws.yaml
113+
```
114+
Kubernetes will allocate a Classic Load Balancer (ELB) in TCP mode with the PROXY protocol enabled to pass the client's information (the IP address and the port). NGINX must be configured to use the PROXY protocol:
115+
* Add the following keys to the config map file `nginx-config.yaml` from the Step 1 :
116+
```
117+
proxy-protocol: "True"
118+
real-ip-header: "proxy_protocol"
119+
set-real-ip-from: "0.0.0.0/0"
120+
```
121+
* Update the config map:
122+
```
123+
kubectl apply -f common/nginx-config.yaml
124+
```
125+
**Note**: For AWS, additional options regarding an allocated load balancer are available, such as the type of a load balancer and SSL termination. Read [this doc](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer) to learn more.
126+
127+
Use the public IP of the load balancer to access the Ingress controller. To get the public IP:
128+
* For GCP or Azure, run:
129+
```
130+
$ kubectl get svc nginx-ingress --namespace=nginx-ingress
131+
```
132+
* In case of AWS ELB, the public IP is not reported by kubectl, as the IP addresses of the ELB are not static and you should not rely on them, but rely on the ELB DNS name instead. However, you can use them for testing purposes. To get the DNS name of the ELB, run:
133+
```
134+
$ kubectl describe svc nginx-ingress --namespace=nginx-ingress
135+
```
136+
You can resolve the DNS name into an IP address using `nslookup`:
137+
```
138+
$ nslookup <dns-name>
139+
```
140+
141+
Read more about the type LoadBalancer [here](https://kubernetes.io/docs/concepts/services-networking/service/#type-loadbalancer).
142+
143+
## 5. Access the Live Activity Monitoring Dashboard
144+
145+
For NGINX Plus, you can access the live activity monitoring dashboard:
146+
1. Use `kubectl port-forward` command to forward connections to port 8080 on your local machine to port 8080 of an NGINX Plus Ingress controller pod (replace <nginx-plus-ingress-pod> with the actual name of a pod):
147+
```
148+
$ kubectl port-forward <nginx-plus-ingress-pod> 8080:8080 --namespace=nginx-ingress
149+
```
150+
1. Open your browser at http://127.0.0.1:8080/status.html to access the dashboard.
151+
152+
## Uninstall the Ingress Controller
153+
154+
Delete the `nginx-ingress` namespace to uninstall the Ingress controller along with all the auxiliary resources that were created:
155+
```
156+
$ kubectl delete namespace nginx-ingress
157+
```

examples/complete-example/README.md

+23-89
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,24 @@
11
# Example
22

3-
## Prerequisites
4-
5-
* Kubernetes 1.2 and later (TLS support for Ingress has been added in 1.2)
6-
* For NGINX Plus:
7-
* Build and make available in your cluster the [Ingress controller](../../nginx-controller) image.
8-
* Update the container image field in the ```nginx-plus-ingress-rc.yaml``` file accordingly.
3+
In this example we deploy the NGINX or NGINX Plus Ingress controller, a simple web application and then configure load balancing for that application using the Ingress resource.
94

105
## Running the Example
116

127
## 1. Deploy the Ingress Controller
138

14-
1. Create a Secret with an SSL certificate and key for the default server of NGINX/NGINX Plus. The default server returns the Not Found page with the 404 status code for all requests for domains for which there are no Ingress rules defined. It is recommended that you use your own certificate and key.
15-
```
16-
$ kubectl create -f default-server-secret.yaml
17-
```
9+
1. Follow the installation [instructions](../../docs/installation.md) to deploy the Ingress controller.
1810

19-
2. Create an Ingress controller either for NGINX or NGINX Plus:
20-
```
21-
$ kubectl create -f nginx-ingress-rc.yaml
11+
1. Save the public IP address of the Ingress controller into a shell variable:
2212
```
23-
or
13+
$ IC_IP=XXX.YYY.ZZZ.III
2414
```
25-
$ kubectl create -f nginx-plus-ingress-rc.yaml
26-
```
27-
28-
3. The controller container exposes ports 80, 443 (and 8080 for NGINX Plus )
29-
on the host it is running on. Make sure to add a firewall rule to allow incoming traffic
30-
though these ports.
3115
3216
## 2. Deploy the Cafe Application
3317
34-
1. Create the coffee and the tea services and replication controllers:
35-
```
36-
$ kubectl create -f tea-rc.yaml
37-
$ kubectl create -f tea-svc.yaml
38-
$ kubectl create -f coffee-rc.yaml
39-
$ kubectl create -f coffee-svc.yaml
40-
```
18+
Create the coffee and the tea deployments and services:
19+
```
20+
$ kubectl create -f cafe.yaml
21+
```
4122
4223
## 3. Configure Load Balancing
4324
@@ -46,80 +27,33 @@ though these ports.
4627
$ kubectl create -f cafe-secret.yaml
4728
```
4829
49-
2. Create an Ingress Resource:
30+
2. Create an Ingress resource:
5031
```
5132
$ kubectl create -f cafe-ingress.yaml
5233
```
5334
5435
## 4. Test the Application
5536
56-
1. Find out the external IP address of the node where the controller is running:
57-
```
58-
$ kubectl get pods -o wide
59-
NAME READY STATUS RESTARTS AGE NODE
60-
coffee-rc-mtjuw 1/1 Running 0 3m kubernetes-minion-iikt
61-
coffee-rc-mu9ns 1/1 Running 0 3m kubernetes-minion-cm0y
62-
nginx-plus-ingress-rc-86kkq 1/1 Running 0 1m kubernetes-minion-iikt
63-
tea-rc-7w3fq 1/1 Running 0 3m kubernetes-minion-iikt
64-
```
65-
66-
```
67-
$ kubectl get node kubernetes-minion-iikt -o json | grep -A 2 ExternalIP
68-
"type": "ExternalIP",
69-
"address": "XXX.YYY.ZZZ.III"
70-
}
71-
```
72-
73-
2. To see that the controller is working, let's curl the coffee and the tea services.
74-
We'll use ```curl```'s --insecure option to turn off certificate verification of our self-signed
37+
1. To access the application, curl the coffee and the tea services. We'll use ```curl```'s --insecure option to turn off certificate verification of our self-signed
7538
certificate and the --resolve option to set the Host header of a request with ```cafe.example.com```
7639
7740
To get coffee:
7841
```
79-
$ curl --resolve cafe.example.com:443:XXX.YYY.ZZZ.III https://cafe.example.com/coffee --insecure
80-
<!DOCTYPE html>
81-
<html>
82-
<head>
83-
<title>Hello from NGINX!</title>
84-
<style>
85-
body {
86-
width: 35em;
87-
margin: 0 auto;
88-
font-family: Tahoma, Verdana, Arial, sans-serif;
89-
}
90-
</style>
91-
</head>
92-
<body>
93-
<h1>Hello!</h1>
94-
<h2>URI = /coffee</h2>
95-
<h2>My hostname is coffee-rc-mu9ns</h2>
96-
<h2>My address is 10.244.0.3:80</h2>
97-
</body>
98-
</html>
42+
$ curl --resolve cafe.example.com:443:$IC_IP https://cafe.example.com/coffee --insecure
43+
Server address: 10.12.0.18:80
44+
Server name: coffee-7586895968-r26zn
45+
...
9946
```
10047
If your rather prefer tea:
10148
```
102-
$ curl --resolve cafe.example.com:443:XXX.YYY.ZZZ.III https://cafe.example.com/tea --insecure
103-
<!DOCTYPE html>
104-
<html>
105-
<head>
106-
<title>Hello from NGINX!</title>
107-
<style>
108-
body {
109-
width: 35em;
110-
margin: 0 auto;
111-
font-family: Tahoma, Verdana, Arial, sans-serif;
112-
}
113-
</style>
114-
</head>
115-
<body>
116-
<h1>Hello!</h1>
117-
<h2>URI = /tea</h2>
118-
<h2>My hostname is tea-rc-w7rjr</h2>
119-
<h2>My address is 10.244.0.5:80</h2>
120-
</body>
121-
</html>
49+
$ curl --resolve cafe.example.com:443:$IC_IP https://cafe.example.com/tea --insecure
50+
Server address: 10.12.0.19:80
51+
Server name: tea-7cd44fcb4d-xfw2x
52+
...
12253
```
12354
124-
3. If you're using NGINX Plus, you can open the live activity monitoring dashboard, which is available at http://XXX.YYY.ZZZ.III:8080/status.html
125-
If you go to the Upstream tab, you'll see: ![dashboard](dashboard.png)
55+
**Note**: If you're using a NodePort service to expose the Ingress controller, replace port 443 in the commands above with the node port that corresponds to port 443.
56+
57+
1. If you're using NGINX Plus, you can open the live activity monitoring dashboard:
58+
1. Follow the [instructions](../../docs/installation.md#5-access-the-live-activity-monitoring-dashboard) to access the dashboard.
59+
1. If you go to the Upstream tab, you'll see: ![dashboard](dashboard.png)

examples/complete-example/cafe.yaml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Deployment
3+
metadata:
4+
name: coffee
5+
spec:
6+
replicas: 2
7+
selector:
8+
matchLabels:
9+
app: coffee
10+
template:
11+
metadata:
12+
labels:
13+
app: coffee
14+
spec:
15+
containers:
16+
- name: coffee
17+
image: nginxdemos/hello:plain-text
18+
ports:
19+
- containerPort: 80
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: coffee-svc
25+
spec:
26+
ports:
27+
- port: 80
28+
targetPort: 80
29+
protocol: TCP
30+
name: http
31+
selector:
32+
app: coffee
33+
---
34+
apiVersion: extensions/v1beta1
35+
kind: Deployment
36+
metadata:
37+
name: tea
38+
spec:
39+
replicas: 3
40+
selector:
41+
matchLabels:
42+
app: tea
43+
template:
44+
metadata:
45+
labels:
46+
app: tea
47+
spec:
48+
containers:
49+
- name: tea
50+
image: nginxdemos/hello:plain-text
51+
ports:
52+
- containerPort: 80
53+
---
54+
apiVersion: v1
55+
kind: Service
56+
metadata:
57+
name: tea-svc
58+
labels:
59+
spec:
60+
ports:
61+
- port: 80
62+
targetPort: 80
63+
protocol: TCP
64+
name: http
65+
selector:
66+
app: tea

examples/complete-example/coffee-rc.yaml

-16
This file was deleted.

0 commit comments

Comments
 (0)