Skip to content

Commit

Permalink
Demo files from the k8s meetup
Browse files Browse the repository at this point in the history
  • Loading branch information
jvassev committed Dec 13, 2018
1 parent 5da7336 commit 951ba47
Show file tree
Hide file tree
Showing 11 changed files with 302 additions and 0 deletions.
2 changes: 2 additions & 0 deletions meetup-2018-11-22/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inject-secrets.sh

7 changes: 7 additions & 0 deletions meetup-2018-11-22/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM debian:stretch-slim

RUN apt-get update -y
RUN apt-get install -y gettext

COPY logger.sh /
ENTRYPOINT ["/logger.sh"]
9 changes: 9 additions & 0 deletions meetup-2018-11-22/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
build:
docker build . -t jvassev/animal-logger:latest

push: build
docker push jvassev/animal-logger:latest

run: build
docker run -ti --rm jvassev/animal-logger:latest

27 changes: 27 additions & 0 deletions meetup-2018-11-22/cat-london.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Namespace
metadata:
name: london

---
apiVersion: v1
kind: Pod
metadata:
name: cat
namespace: london
labels:
animal: cat
breed: munchkin
spec:
containers:
- image: jvassev/animal-logger
imagePullPolicy: Always
name: main
env:
- name: ANIMAL
value: cat
- name: SOUND
value: meow
volumes:
- name: logs
emptyDir: {}
27 changes: 27 additions & 0 deletions meetup-2018-11-22/cat-paris.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: v1
kind: Namespace
metadata:
name: paris

---
apiVersion: v1
kind: Pod
metadata:
name: cat
namespace: paris
labels:
animal: cat
breed: sphynx
spec:
containers:
- image: jvassev/animal-logger
imagePullPolicy: Always
name: main
env:
- name: ANIMAL
value: cat
- name: SOUND
value: miaou
volumes:
- name: logs
emptyDir: {}
28 changes: 28 additions & 0 deletions meetup-2018-11-22/config-london.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!./inject-secrets.sh
apiVersion: v1
kind: Namespace
metadata:
name: london

---
apiVersion: v1
kind: ConfigMap
metadata:
name: fluentd-config
namespace: london
data:
fluent.conf: |
<source>
@type tail
path /var/logs/dogd.log
labels animal=dog, _container=main
<parse>
#@type json
@type none
</parse>
</source>
<match kube.paris.**>
@type loggly
loggly_url https://logs-01.loggly.com/inputs/$LOGGLY_TOKEN/tag/fluentd
</match>
37 changes: 37 additions & 0 deletions meetup-2018-11-22/config-paris.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!./inject-secrets.sh
apiVersion: v1
kind: Namespace
metadata:
name: paris

---
apiVersion: v1
kind: ConfigMap
metadata:
name: fluentd-config
namespace: paris
data:
fluent.conf: |
<match **>
@type loggly
loggly_url https://logs-01.loggly.com/inputs/$LOGGLY_TOKEN/tag/fluentd
</match>
# <match **>
# @type elasticsearch
# include_tag_key false
# host "cloud.humio.com"
# path "/api/v1/dataspaces/sandbox/ingest/elasticsearch/"
# scheme "https"
# port "443"
# user "$HUMIO_KEY"
# password ""
# logstash_format true
# reload_connections "true"
# logstash_prefix "fluentd:kubernetes2humio"
# buffer_chunk_limit 1M
# buffer_queue_limit 32
# flush_interval 1s
# max_retry_wait 30
# disable_retry_limit
# num_threads 8
# </match>
32 changes: 32 additions & 0 deletions meetup-2018-11-22/dog-london.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: Namespace
metadata:
name: london

---
apiVersion: v1
kind: Pod
metadata:
name: dog
namespace: london
labels:
animal: dog
breed: pug
spec:
containers:
- image: jvassev/animal-logger
imagePullPolicy: Always
name: main
env:
- name: ANIMAL
value: dog
- name: SOUND
value: bark-bark
- name: FILE
value: /var/logs/dogd.log
volumeMounts:
- name: logs
mountPath: /var/logs
volumes:
- name: logs
emptyDir: {}
32 changes: 32 additions & 0 deletions meetup-2018-11-22/dog-paris.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: v1
kind: Namespace
metadata:
name: paris

---
apiVersion: v1
kind: Pod
metadata:
name: dog
namespace: paris
labels:
animal: dog
breed: bulldog
spec:
containers:
- image: jvassev/animal-logger
imagePullPolicy: Always
name: main
env:
- name: ANIMAL
value: dog
- name: SOUND
value: ouah, ouah
- name: FILE
value: /var/logs/dogd.log
volumeMounts:
- name: logs
mountPath: /var/logs
volumes:
- name: logs
emptyDir: {}
23 changes: 23 additions & 0 deletions meetup-2018-11-22/logger.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

ANIMAL="${ANIMAL:-some unknown animal}"
SOUND="${SOUND:-???}"


while true; do
export now="$(date --rfc-3339=seconds)"
export msg="I am $ANIMAL and I say '${SOUND}' #msgid$((var++))"
export level="INFO"

if [[ $(($RANDOM % 10)) == 0 ]]; then
msg="Severe: $ANIMAL is unable to say '${SOUND}' #msgid$((var++))"
level="ERROR"
fi
echo "$now [$level] $msg"

if [[ "$FILE" != '' ]]; then
echo '{ "timestamp": "$now", "level": "$level", "message": "$msg"}' | envsubst >> $FILE
fi

sleep 2
done
78 changes: 78 additions & 0 deletions meetup-2018-11-22/snippetes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# humio
@type elasticsearch
include_tag_key false
host "cloud.humio.com"
path "/api/v1/dataspaces/sandbox/ingest/elasticsearch/"
scheme "https"
port "443"
user "$HUMIO_KEY"
password ""
logstash_format true
reload_connections "true"
logstash_prefix "fluentd:kubernetes2humio"
buffer_chunk_limit 1M
buffer_queue_limit 32
flush_interval 1s
max_retry_wait 30
disable_retry_limit
num_threads 8



# loggly
@type loggly
loggly_url https://logs-01.loggly.com/inputs/$LOGGLY_TOKEN/tag/fluentd



# papetrail
@type papertrail
papertrail_host $PT_HOST
papertrail_port $PT_PORT
flush_interval 30



# clone
<match $labels(animal=dog, breed=pug)>
@type copy

<store>
</store>

<store>
</store>
</match>



# from file
<source>
@type mounted_file
path /var/log/dogd.log
labels animal=dog, _container=main
<parse>
@type none
</parse>
</source>




# json
<filter $labels(...)>
@type parser
format json
key_name log
reserve_data true
suppress_parse_error_log true
</filter>


# show config
POD=log-router-log-router-z64mc

kubectl exec -n infra-system $POD -c reloader -- ls -l /fluentd/etc/
kubectl exec -n infra-system $POD -c reloader -- cat /fluentd/etc/ns-london.conf
kubectl exec -n infra-system $POD -c reloader -- cat /fluentd/etc/ns-paris.conf
kubectl exec -n infra-system $POD -c reloader -- cat /fluentd/etc/fluent.conf

0 comments on commit 951ba47

Please sign in to comment.