Skip to content

Commit

Permalink
Minor fixes and add a basic example.
Browse files Browse the repository at this point in the history
  • Loading branch information
amwat committed Dec 11, 2019
1 parent 4ec8b1d commit daacdbb
Show file tree
Hide file tree
Showing 2 changed files with 144 additions and 56 deletions.
56 changes: 0 additions & 56 deletions site/content/docs/user/ingress-nginx.md

This file was deleted.

144 changes: 144 additions & 0 deletions site/content/docs/user/ingress.md
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
```

0 comments on commit daacdbb

Please sign in to comment.