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 user guide for ingress nginx. #1159

Merged
merged 5 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 167 additions & 0 deletions site/content/docs/user/ingress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
title: "Ingress"
menu:
main:
parent: "user"
identifier: "user-ingress"
weight: 3
amwat marked this conversation as resolved.
Show resolved Hide resolved
---

## Setting Up An Ingress Controller

amwat marked this conversation as resolved.
Show resolved Hide resolved
We can leverage KIND's `extraPortMapping` config option when creating a cluster to
forward ports from the host to an ingress controller running on a node. We can also specify
custom node label by using `node-labels` in the kubeadm `InitConfiguration`, to be used
by the ingress controller `nodeSelector`.
The following ingress controllers are known to work:

- [Ingress NGINX](#ingress-nginx)

### Ingress NGINX

Create a kind cluster with `extraPortMappings` and `node-labels`.

```shell script
cat <<EOF | kind create cluster --config=-
amwat marked this conversation as resolved.
Show resolved Hide resolved
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
apiVersion: kubeadm.k8s.io/v1beta2
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
authorization-mode: "AlwaysAllow"
Copy link
Member

Choose a reason for hiding this comment

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

Wait a sec, what's this about? 😅

Copy link
Member

Choose a reason for hiding this comment

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

i don't think this is needed for nginx ingress and it's not a recommended practice.

Copy link
Member

@aledbf aledbf May 3, 2020

Choose a reason for hiding this comment

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

I can confirm this is not required or recommended in ingress-nginx. Maybe it is required for something else?

Copy link
Member

Choose a reason for hiding this comment

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

i suspect this is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, if it's working without it we can probably safely remove this.

extraPortMappings:
- containerPort: 80
hostPort: 80
- containerPort: 443
hostPort: 443
EOF
```
Apply the [mandatory ingress-nginx components](https://kubernetes.github.io/ingress-nginx/deploy/#prerequisite-generic-deployment-command).

```shell script
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
```
Apply kind specific patches

```yaml
spec:
template:
spec:
containers:
- name: nginx-ingress-controller
ports:
- containerPort: 80
# Proxy the host port 80 for http
hostPort: 80
- containerPort: 443
# Proxy the host port 443 for https
hostPort: 443
nodeSelector:
# schedule it on the control-plane node
ingress-ready: 'true'
tolerations:
# tolerate the the control-plane taints
- key: node-role.kubernetes.io/master
operator: Equal
effect: NoSchedule
```

```shell script
kubectl patch deployments -n ingress-nginx nginx-ingress-controller -p "$(curl https://kind.sigs.k8s.io/manifests/ingress/nginx/patch.yaml)"
```


Now you will want to checkout [Using Ingress](#using-ingress)


## Using Ingress

The following example creates simple http-echo services
and an Ingress object to route to these services.

```yaml
kind: Pod
apiVersion: v1
metadata:
name: foo-app
labels:
app: foo
spec:
containers:
- name: foo-app
image: hashicorp/http-echo
args:
- "-text=foo"
---
kind: Service
apiVersion: v1
metadata:
name: foo-service
spec:
selector:
app: foo
ports:
- port: 5678 # Default port used by the image
---
kind: Pod
apiVersion: v1
metadata:
name: bar-app
labels:
app: bar
spec:
containers:
- name: bar-app
image: hashicorp/http-echo
args:
- "-text=bar"
---
kind: Service
apiVersion: v1
metadata:
name: bar-service
spec:
selector:
app: bar
ports:
- port: 5678 # Default port used by the image
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /foo
backend:
serviceName: foo-service
servicePort: 5678
- path: /bar
backend:
serviceName: bar-service
servicePort: 5678
---
```

Apply the contents

```shell script
kubectl apply -f https://kind.sigs.k8s.io/manifests/ingress/nginx/example.yaml
```

Now verify that the ingress works
BenTheElder marked this conversation as resolved.
Show resolved Hide resolved

```shell script
curl localhost/foo # should output "foo"
curl localhost/bar # should output "bar"
```
amwat marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion site/content/docs/user/known-issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ menu:
main:
parent: "user"
identifier: "known-issues"
weight: 3
weight: 2
---
# Known Issues

Expand Down
65 changes: 65 additions & 0 deletions site/static/manifests/ingress/nginx/example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
kind: Pod
apiVersion: v1
metadata:
name: foo-app
labels:
app: foo
spec:
containers:
- name: foo-app
image: hashicorp/http-echo
args:
- "-text=foo"
---
kind: Service
apiVersion: v1
metadata:
name: foo-service
spec:
selector:
app: foo
ports:
- port: 5678 # Default port used by the image
---
kind: Pod
apiVersion: v1
metadata:
name: bar-app
labels:
app: bar
spec:
containers:
- name: bar-app
image: hashicorp/http-echo
args:
- "-text=bar"
---
kind: Service
apiVersion: v1
metadata:
name: bar-service
spec:
selector:
app: bar
ports:
- port: 5678 # Default port used by the image
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /foo
backend:
serviceName: foo-service
servicePort: 5678
- path: /bar
backend:
serviceName: bar-service
servicePort: 5678
---
20 changes: 20 additions & 0 deletions site/static/manifests/ingress/nginx/patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
spec:
template:
spec:
containers:
- name: nginx-ingress-controller
ports:
- containerPort: 80
# Proxy the host port 80 for http
hostPort: 80
- containerPort: 443
# Proxy the host port 443 for https
hostPort: 443
nodeSelector:
# schedule it on the control-plane node
ingress-ready: 'true'
tolerations:
# tolerate the the control-plane taints
- key: node-role.kubernetes.io/master
operator: Equal
effect: NoSchedule