-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Minor fixes and add a basic example.
- Loading branch information
Showing
2 changed files
with
144 additions
and
56 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
--- | ||
title: Ingress" | ||
menu: | ||
main: | ||
parent: "user" | ||
identifier: "user-ingress" | ||
weight: 3 | ||
--- | ||
# Ingress | ||
|
||
[Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) in kind can be setup by exposing ports `80(http)` and `443(https)` | ||
from the host to the ingress controller using hostPorts. | ||
|
||
## Create A Cluster with Ingress NGINX | ||
|
||
The following shell script will create a kind cluster, deploy | ||
the standard ingress-nginx components, and apply the necessary patches. | ||
|
||
```bash | ||
#!/bin/sh | ||
set -o errexit | ||
|
||
# Create cluster with hostPorts opened for http and https | ||
cat <<EOF | kind create cluster --config=- | ||
kind: Cluster | ||
apiVersion: kind.x-k8s.io/v1alpha4 | ||
nodes: | ||
- role: control-plane | ||
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 | ||
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml | ||
|
||
# Apply kind specific patches | ||
kubectl patch deployments -n ingress-nginx nginx-ingress-controller -p "$(cat<<EOF | ||
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 | ||
node-role.kubernetes.io/master: '' | ||
tolerations: | ||
# tolerate the the control-plane taints | ||
- key: node-role.kubernetes.io/master | ||
operator: Equal | ||
effect: NoSchedule | ||
EOF | ||
)" | ||
``` | ||
|
||
## Using the Ingress | ||
|
||
The following example creates simple http-echo services | ||
and an Ingress object to route to these services. | ||
|
||
```bash | ||
cat <<EOF | kubectl apply -f - | ||
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 | ||
--- | ||
EOF | ||
``` | ||
Now verify that the ingress works | ||
```bash | ||
curl localhost/foo | ||
curl localhost/bar | ||
``` |