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 secret creation to docs for kubernetes backend #2374

Merged
merged 1 commit into from
Nov 9, 2017

Conversation

shadycuz
Copy link
Contributor

@shadycuz shadycuz commented Nov 7, 2017

What does this PR do?

Adds additional documentation to help people setup basic auth with kubernetes ingress.

Motivation

I was unable to easily find the information I needed to create the secret. I had to resort to tracking down the original PR for that feature.

More

  • Added/updated documentation

Additional Notes

I think the instructions to create the dashboard auth user and password (types of encryption) is the same for adding auth to an ingress but I could not confirm so I let it as is.

Note: Sublime must have removed some invisible trailing spaces, I see a bunch of lines that are modified but not changed.

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. 👍

In Markdown, spaces at the end of a sentence have a meaning:

When you do want to insert a <br /> break tag using Markdown, you end a line with two or more spaces, then type return.

https://daringfireball.net/projects/markdown/syntax#p

@@ -121,7 +121,7 @@ Is possible to add additional authentication annotations in the Ingress rule.
The source of the authentication is a secret that contains usernames and passwords inside the the key auth.

- `ingress.kubernetes.io/auth-type`: `basic`
- `ingress.kubernetes.io/auth-secret`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have

Enable backend sticky sessions (DEPRECATED)

You can find here an example [ingress](https://raw.githubusercontent.com/containous/traefik/master/examples/k8s/cheese-ingress.yaml) and [replication controller](https://raw.githubusercontent.com/containous/traefik/master/examples/k8s/traefik.yaml).

Additionally, an annotation can be used on Kubernetes services to set the [circuit breaker expression](/basics/#backends) for a backend.

- `traefik.backend.circuitbreaker: <expression>`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces?

@@ -84,27 +84,27 @@ See [label-selectors](https://kubernetes.io/docs/concepts/overview/working-with-

Annotations can be used on containers to override default behaviour for the whole Ingress resource:

- `traefik.frontend.rule.type: PathPrefixStrip`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces?

Override the default frontend rule type. Default: `PathPrefix`.
- `traefik.frontend.priority: "3"`
Override the default frontend rule priority.

Annotations can be used on the Kubernetes service to override default behaviour:

- `traefik.backend.loadbalancer.method=drr`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces?

Override the default `wrr` load balancer algorithm
- `traefik.backend.loadbalancer.stickiness=true`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces? (just keep 2 spaces)

Manually set the cookie name for sticky sessions
- `traefik.backend.loadbalancer.sticky=true`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces? (just keep 2 spaces)

@@ -75,9 +75,9 @@ For namespaced restrictions, one RoleBinding is required per watched namespace a

It is possible to use Træfik with a [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) or a [DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) object,
whereas both options have their own pros and cons:

- The scalability is much better when using a Deployment, because you will have a Single-Pod-per-Node model when using the DeaemonSet.
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces?

@@ -75,9 +75,9 @@ For namespaced restrictions, one RoleBinding is required per watched namespace a

It is possible to use Træfik with a [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) or a [DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) object,
whereas both options have their own pros and cons:

- The scalability is much better when using a Deployment, because you will have a Single-Pod-per-Node model when using the DeaemonSet.
- It is possible to exclusively run a Service on a dedicated set of machines using taints and tolerations with a DaemonSet.
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces?

@@ -321,7 +321,7 @@ kubectl apply -f https://raw.githubusercontent.com/containous/traefik/master/exa

Now lets setup an entry in our /etc/hosts file to route `traefik-ui.minikube` to our cluster.

In production you would want to set up real dns entries.
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces?

@@ -627,7 +680,7 @@ Note that priority values must be quoted to avoid them being interpreted as numb
## Forwarding to ExternalNames

When specifying an [ExternalName](https://kubernetes.io/docs/concepts/services-networking/service/#services-without-selectors),
Træfik will forward requests to the given host accordingly and use HTTPS when the Service port matches 443.
Copy link
Contributor

Choose a reason for hiding this comment

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

could you restore the spaces?

@shadycuz
Copy link
Contributor Author

shadycuz commented Nov 7, 2017

@ldez I have fixed my editor to stop doing that =)

Spaces are back in place.

@@ -330,6 +330,59 @@ echo "$(minikube ip) traefik-ui.minikube" | sudo tee -a /etc/hosts

We should now be able to visit [traefik-ui.minikube](http://traefik-ui.minikube) in the browser and view the Træfik Web UI.

## Basic Authentication
Is possible to add additional authentication annotations in the Ingress rule. The source of the authentication is a secret that contains usernames and passwords inside the the key auth.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add a blank line after the heading?

* Basic authentication only
* Realm not configurable; only traefikdefault
* Secret is in same namespace as ingress rule
* Secret must contain only single file
Copy link
Contributor

@timoreimann timoreimann Nov 7, 2017

Choose a reason for hiding this comment

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

The whole paragraph basically duplicates what can already be found in the Kubernetes configuration documentation. Instead of repeating, I suggest we only mention that a certain number of restrictions exist in general, and leave a pointer where to find them.


#### Creating the Secret

1. `htpasswd -c ./auth myusername`
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you prepend the actual htpasswd call by a sentence explaining what we're doing? Something like Use htpasswd to create a file containing the username and the base64-encoded password:

myusername:$apr1$78Jyn/1K$ERHKVRPPlzAX8eBtLuvRZ0
```

2. `kubectl --namespace=monitoring create secret generic mysecret --from-file auth`
Copy link
Contributor

Choose a reason for hiding this comment

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

A quick sentence here that we are creating a secret containing the htpasswd file in a namespace called monitoring?


**Note:** Secret must be in same namespace as the ingress rule.

3. Now we will create our ingress using the following annotations to specify we want basic auth and that the username and password is stored in "mysecret".
Copy link
Contributor

@timoreimann timoreimann Nov 7, 2017

Choose a reason for hiding this comment

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

Can you replace the we form by you / the imperative in order to be consistent with the rest of the guide? That is, rephrase the sentence like

Create the ingress using the following annotations to specify basic auth and that the username and password are stored in "mysecret".

- `ingress.kubernetes.io/auth-type: "basic"`
- `ingress.kubernetes.io/auth-secret: "mysecret"`

I saved the following in prometheus-ingress.yaml...
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use the passive form in the phrasing like

Following is a full ingress example based on Prometheus:

servicePort: 80
```

`kubectl create -f prometheus-ingress.yaml -n monitoring`
Copy link
Contributor

Choose a reason for hiding this comment

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

Another short explanation like

You can apply the example as following:

@shadycuz
Copy link
Contributor Author

shadycuz commented Nov 7, 2017

@timoreimann I didn't know the docs in the repo were used to generate the site. Let me clean that up.

@@ -330,6 +330,61 @@ echo "$(minikube ip) traefik-ui.minikube" | sudo tee -a /etc/hosts

We should now be able to visit [traefik-ui.minikube](http://traefik-ui.minikube) in the browser and view the Træfik Web UI.

## Basic Authentication

It's possible to add additional authentication annotations in the Ingress rule. The source of the authentication is a secret that contains usernames and passwords inside the the key auth. To read about basic auth limitations see the [Kubernetes Ingress](https://docs.traefik.io/configuration/backends/kubernetes/) configuration page.
Copy link
Contributor

@timoreimann timoreimann Nov 7, 2017

Choose a reason for hiding this comment

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

It should be possible to use a relative URL like /configuration/backends/kubernetes. For an example, see here (3rd line from the top; note that it's the "reverse direction" but it's conceptually the same).

@shadycuz
Copy link
Contributor Author

shadycuz commented Nov 7, 2017

@timoreimann Link is working inside your neat little deploy preview =)

@shadycuz
Copy link
Contributor Author

shadycuz commented Nov 7, 2017

@timoreimann something is wrong with code block now let me look into it.

@@ -330,6 +330,61 @@ echo "$(minikube ip) traefik-ui.minikube" | sudo tee -a /etc/hosts

We should now be able to visit [traefik-ui.minikube](http://traefik-ui.minikube) in the browser and view the Træfik Web UI.

## Basic Authentication

It's possible to add additional authentication annotations in the Ingress rule. The source of the authentication is a secret that contains usernames and passwords inside the the key auth. To read about basic auth limitations see the [Kubernetes Ingress](/configuration/backends/kubernetes) configuration page.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could put one sentence by line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move the sentence up a line? @ldez


1. Use `htpasswd` to create a file containing the username and the base64-encoded password:

`htpasswd -c ./auth myusername`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you use this syntax:

```
htpasswd -c ./auth myusername
```

a file with the following:

```
~$ cat auth
Copy link
Contributor

Choose a reason for hiding this comment

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

could you remove ~$?


2. Now use `kubectl` to create a secret in the monitoring namespace using the file created by `htpasswd`.

`kubectl create secret generic mysecret --from-file auth --namespace=monitoring`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you use this syntax:

```
kubectl create secret generic mysecret --from-file auth --namespace=monitoring
```


You can apply the example ingress as following:

`kubectl create -f prometheus-ingress.yaml -n monitoring`
Copy link
Contributor

Choose a reason for hiding this comment

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

could you use this syntax:

```
kubectl create -f prometheus-ingress.yaml -n monitoring
```


Following is a full ingress example based on Prometheus:

```yaml
Copy link
Contributor

Choose a reason for hiding this comment

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

@ldez FWIW, except for one case, the guide uses yaml everywhere else.

Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

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

Could you remove all spaces at the start of each line of all code blocks?

https://github.com/containous/traefik/blob/master/CONTRIBUTING.md#documentation

3. Create the ingress using the following annotations to specify basic auth and that the username and password is stored in "mysecret".

- ingress.kubernetes.io/auth-type: "basic"
- ingress.kubernetes.io/auth-secret: "mysecret"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you surround each annotation with backticks?

@shadycuz
Copy link
Contributor Author

shadycuz commented Nov 8, 2017

Looks better but the numbers are wrong for the steps

@shadycuz
Copy link
Contributor Author

shadycuz commented Nov 8, 2017

@ldez Nice, It finally looks right =)

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

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

@shadycuz Thanks a lots for this PR 👍
Only one minor note.

## Basic Authentication

It's possible to add additional authentication annotations in the Ingress rule.
The source of the authentication is a secret that contains usernames and passwords inside the the key auth.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove one of the the in the the key auth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nmengin that typo appears to have been in the code base... It's live on the docs site.

@ldez
Copy link
Contributor

ldez commented Nov 8, 2017

@shadycuz could you remove the 2 merge commits?

I will rebase your PR on 1.4 branch when it will ready

@shadycuz
Copy link
Contributor Author

shadycuz commented Nov 8, 2017 via email

```shell
cat auth
```
```
Copy link
Contributor

@timoreimann timoreimann Nov 8, 2017

Choose a reason for hiding this comment

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

Is the extra block intentional? It looks a bit strange on the rendered output.

I'd suggest to simply drop the cat auth part. It's clear from the paragraph right above that we're talking about the content of the auth file, no need to show the extra cat call IMHO.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have split the block: because it's more easy to copy-paste (with the end of block button)

Copy link
Contributor

Choose a reason for hiding this comment

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

OK 👍

Copy link
Contributor

@timoreimann timoreimann left a comment

Choose a reason for hiding this comment

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

LGTM -- great work, thanks!

@shadycuz
Copy link
Contributor Author

shadycuz commented Nov 9, 2017

waiting for me to undo the merges or not?

@timoreimann
Copy link
Contributor

Ah yeah, if you haven't done so yet and @ldez asked for it, you should do it.

Should hopefully not affect my LGTM though.

@shadycuz
Copy link
Contributor Author

shadycuz commented Nov 9, 2017

Cool I think it worked, I did a hard reset to before the merges, and then noticed the cat was mising, added it back and pushed.

Copy link
Contributor

@nmengin nmengin left a comment

Choose a reason for hiding this comment

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

LGTM 👏 📖

@ldez ldez added this to the 1.4 milestone Nov 9, 2017
Copy link
Contributor

@ldez ldez left a comment

Choose a reason for hiding this comment

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

LGTM

@traefiker traefiker merged commit 56affb9 into traefik:v1.4 Nov 9, 2017
@shadycuz shadycuz deleted the kubedocs branch November 9, 2017 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants