Introduce working example of nginx controller with rbac

This commit is contained in:
Michael Grosser 2017-06-08 06:34:36 +00:00
parent d556cc07b6
commit ec6efbd9d3
4 changed files with 115 additions and 56 deletions

View file

@ -1,6 +1,6 @@
# Role Based Access Control
This example demontrates how to apply role based access control
This example demontrates how to apply an nginx ingress controller with role based access control
## Overview
@ -89,28 +89,20 @@ change as well.
`ClusterRoleBinding`, and `RoleBinding`.
```sh
kubectl create -f ./nginx-ingress-controller-rbac.yml
kubectl create -f https://raw.githubusercontent.com/kubernetes/ingress/master/examples/rbac/nginx/nginx-ingress-controller-rbac.yml
```
2. Create the nginx-ingress-controller
2. Create default backend
```sh
kubectl create -f https://raw.githubusercontent.com/kubernetes/ingress/master/examples/rbac/nginx/default-backend.yml
```
3. Create the nginx-ingress-controller
For this example to work, the Service must be in the nginx-ingress namespace:
```yaml
apiVersion: v1
kind: Service
metadata:
name: nginx-ingress
namespace: nginx-ingress #match namespace of service account and role
spec:
type: LoadBalancer
ports:
- port: 80
name: http
- port: 443
name: https
selector:
k8s-app: nginx-ingress-lb
```sh
kubectl create -f https://raw.githubusercontent.com/kubernetes/ingress/master/examples/rbac/nginx/nginx-ingress-controller.yml
```
The serviceAccountName associated with the containers in the deployment must
@ -118,42 +110,7 @@ match the serviceAccount from nginx-ingress-controller-rbac.yml The namespace
references in the Deployment metadata, container arguments, and POD_NAMESPACE
should be in the nginx-ingress namespace.
```yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: nginx-ingress-controller
#match namespace of service account and role
namespace: nginx-ingress
spec:
replicas: 2
template:
metadata:
labels:
k8s-app: nginx-ingress-lb
spec:
#match name of service account
serviceAccountName: nginx-ingress-serviceaccount
containers:
- name: nginx-ingress-controller
image: gcr.io/google_containers/nginx-ingress-controller:version
#namespace matching is required in some arguments
args:
- /nginx-ingress-controller
- --default-backend-service=default/default-http-backend
- --default-ssl-certificate=$(POD_NAMESPACE)/tls-certificate
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
#match namespace of service account and role
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
- containerPort: 80
- containerPort: 443
4. Create ingress service
```sh
kubectl create -f https://raw.githubusercontent.com/kubernetes/ingress/master/examples/rbac/nginx/nginx-ingress-controller-service.yml
```