Skip to content

Commit

Permalink
updated field
Browse files Browse the repository at this point in the history
  • Loading branch information
theemadnes committed Aug 7, 2020
1 parent b3fdca0 commit e18c1ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# whereami

*NOTE - this repo has been moved to https://github.com/GoogleCloudPlatform/kubernetes-engine-samples/tree/master/whereami*

`whereami` is a simple Kubernetes-oriented python app for describing the location of the pod serving a request via its attributes (cluster name, cluster region, pod name, namespace, service account, etc). This is useful for a variety of demos where you just need to understand how traffic is getting to and returning from your app.

### Simple deployment

`whereami` is a single-container app, designed and packaged to run on Kubernetes. In it's simplest form it can be deployed in a single line with only a few parameters.

```bash
$ kubectl run --image=gcr.io/alexmattson-scratch/whereami:v1.1.0 --expose --port 8080 whereami
$ kubectl run --image=gcr.io/alexmattson-scratch/whereami:v1.0.1 --expose --port 8080 whereami
```

The `whereami` pod listens on port `8080` and returns a very simple JSON response that indicates who is responding and where they live.
Expand Down Expand Up @@ -81,7 +79,7 @@ spec:
serviceAccountName: whereami-ksa
containers:
- name: whereami
image: gcr.io/alexmattson-scratch/whereami:v1.1.0
image: gcr.io/alexmattson-scratch/whereami:v1.0.1
ports:
- name: http
containerPort: 8080 #The application is listening on port 8080
Expand Down Expand Up @@ -286,7 +284,7 @@ $ for i in {1..3}; do curl $ENDPOINT -s | jq '{frontend: .pod_name, backend: .ba

### Include all received headers in the response

`whereami` has an additional feature flag that, when enabled, will include all received headers in its reply. If, in `k8s/configmap.yaml`, `ECHO_HEADERS` is set to `True`, the response payload will include an `echo_headers` field, populated with the headers included in the client's request.
`whereami` has an additional feature flag that, when enabled, will include all received headers in its reply. If, in `k8s/configmap.yaml`, `ECHO_HEADERS` is set to `True`, the response payload will include a `headers` field, populated with the headers included in the client's request.

#### Step 1 - Deploy whereami with header echoing enabled

Expand All @@ -312,7 +310,7 @@ Curl the endpoint to get the response. Yet again, we use [jq]() to provide a lit
$ curl $ENDPOINT -s | jq .
{
"cluster_name": "cluster-1",
"echo_headers": {
"headers": {
"Accept": "*/*",
"Host": "34.67.116.242",
"User-Agent": "curl/7.64.1"
Expand Down
8 changes: 7 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,13 @@ def home(path):

if echo_headers == 'True':

payload['echo_headers'] = {k:v for k, v in request.headers.items()}
try:

payload['headers'] = {k:v for k, v in request.headers.items()}

except:

logging.warning("Unable to capture inbound headers.")

return jsonify(payload)

Expand Down

0 comments on commit e18c1ac

Please sign in to comment.