-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 kubernetes manifests #5349
Merged
Merged
Add kubernetes manifests #5349
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0083ca2
Add kubernetes manifests
exekias 31f8ea0
Add travis tests
exekias b892d59
Add packaging
exekias 0b0349e
Add docs
exekias 7d62181
Update CHANGELOG
exekias dfdba8c
Fix Makefile
exekias 842a541
Check k8s health every second
exekias 23306e1
Merge branch 'master' into kubernetes-manifests
tsg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*-kubernetes-*.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# This script assumes Docker is already installed | ||
#!/bin/bash | ||
|
||
set -x | ||
|
||
# set docker0 to promiscuous mode | ||
sudo ip link set docker0 promisc on | ||
|
||
# install etcd | ||
wget https://github.com/coreos/etcd/releases/download/$TRAVIS_ETCD_VERSION/etcd-$TRAVIS_ETCD_VERSION-linux-amd64.tar.gz | ||
tar xzf etcd-$TRAVIS_ETCD_VERSION-linux-amd64.tar.gz | ||
sudo mv etcd-$TRAVIS_ETCD_VERSION-linux-amd64/etcd /usr/local/bin/etcd | ||
rm etcd-$TRAVIS_ETCD_VERSION-linux-amd64.tar.gz | ||
rm -rf etcd-$TRAVIS_ETCD_VERSION-linux-amd64 | ||
|
||
# download kubectl | ||
wget https://storage.googleapis.com/kubernetes-release/release/$TRAVIS_KUBE_VERSION/bin/linux/amd64/kubectl | ||
chmod +x kubectl | ||
sudo mv kubectl /usr/local/bin/kubectl | ||
|
||
# download kubernetes | ||
git clone https://github.com/kubernetes/kubernetes $HOME/kubernetes | ||
|
||
# install cfssl | ||
go get -u github.com/cloudflare/cfssl/cmd/... | ||
|
||
pushd $HOME/kubernetes | ||
git checkout $TRAVIS_KUBE_VERSION | ||
kubectl config set-credentials myself --username=admin --password=admin | ||
kubectl config set-context local --cluster=local --user=myself | ||
kubectl config set-cluster local --server=http://localhost:8080 | ||
kubectl config use-context local | ||
|
||
# start kubernetes in the background | ||
sudo PATH=$PATH:/home/travis/.gimme/versions/go1.7.linux.amd64/bin/go \ | ||
KUBE_ENABLE_CLUSTER_DNS=true \ | ||
hack/local-up-cluster.sh & | ||
popd | ||
|
||
# Wait until kube is up and running | ||
TIMEOUT=0 | ||
TIMEOUT_COUNT=800 | ||
until $(curl --output /dev/null --silent http://localhost:8080) || [ $TIMEOUT -eq $TIMEOUT_COUNT ]; do | ||
echo "Kube is not up yet" | ||
let TIMEOUT=TIMEOUT+1 | ||
sleep 1 | ||
done | ||
|
||
if [ $TIMEOUT -eq $TIMEOUT_COUNT ]; then | ||
echo "Kubernetes is not up and running" | ||
exit 1 | ||
fi | ||
|
||
echo "Kubernetes is deployed and reachable" | ||
|
||
# Try and sleep before issuing chown. Currently, Kubernetes is started by | ||
# a command that is run in the background. Technically Kubernetes could be | ||
# up and running, but those files might not exist yet as the previous command | ||
# could create them after Kube starts successfully. | ||
sleep 5 | ||
|
||
sudo chown -R $USER:$USER $HOME/.kube | ||
|
||
# Have seen issues where chown does not instantly change file permissions. | ||
# When this happens the build.sh cript can have failures. | ||
sleep 30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
ALL=filebeat metricbeat | ||
BEAT_VERSION=$(shell head -n 1 ../../libbeat/docs/version.asciidoc | cut -c 17- ) | ||
|
||
all: ${ALL:=-kubernetes.yaml} | ||
|
||
test: all | ||
ls *-kubernetes-${BEAT_VERSION}.yaml | ||
for FILE in $(shell ls *-kubernetes-${BEAT_VERSION}.yaml); do \ | ||
BEAT=$$(echo $$FILE | cut -d \- -f 1); \ | ||
kubectl create -f $$FILE; \ | ||
done | ||
|
||
clean: | ||
@for f in $(ALL); do rm -f "$$f-kubernetes-${BEAT_VERSION}.yaml"; done | ||
|
||
%-kubernetes.yaml: %/*.yaml | ||
@echo "Generating $*-kubernetes-${BEAT_VERSION}.yaml" | ||
@rm -f $*-kubernetes-${BEAT_VERSION}.yaml | ||
@for f in $(shell ls $*/*.yaml); do \ | ||
sed "s/%VERSION%/${BEAT_VERSION}/g" $$f >> $*-kubernetes-${BEAT_VERSION}.yaml; \ | ||
echo --- >> $*-kubernetes-${BEAT_VERSION}.yaml; \ | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Beats Kubernetes manifests examples | ||
|
||
## Getting started | ||
|
||
This is the list of officially supported Beats, with example manifests to run | ||
them in Kubernetes: | ||
|
||
Beat | Description | ||
---- | ---- | ||
[filebeat](filebeat) | Tails and ships logs | ||
[metricbeat](metricbeat) | Fetches sets of metrics from the operating system and services |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Filebeat | ||
|
||
## Ship logs from Kubernetes to Elasticsearch | ||
|
||
### Kubernetes DaemonSet | ||
|
||
By deploying filebeat as a [DaemonSet](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset/) | ||
we ensure we get a running filebeat daemon on each node of the cluster. | ||
|
||
Docker logs host folder (`/var/lib/docker/containers`) is mounted on the | ||
filebeat container. Filebeat will start a prospector for these files and start | ||
harvesting them as they appear. | ||
|
||
Everything is deployed under `kube-system` namespace, you can change that by | ||
updating YAML manifests under this folder. | ||
|
||
### Settings | ||
|
||
We use official [Beats Docker images](https://github.com/elastic/beats-docker), | ||
as they allow external files configuration, a [ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/) | ||
is used for kubernetes specific settings. Check [filebeat-configmap.yaml](filebeat-configmap.yaml) | ||
for details. | ||
|
||
Also, [filebeat-daemonset.yaml](filebeat-daemonset.yaml) uses a set of environment | ||
variables to configure Elasticsearch output: | ||
|
||
Variable | Default | Description | ||
-------- | ------- | ----------- | ||
ELASTICSEARCH_HOST | elasticsearch | Elasticsearch host | ||
ELASTICSEARCH_PORT | 9200 | Elasticsearch port | ||
ELASTICSEARCH_USERNAME | elastic | Elasticsearch username for HTTP auth | ||
ELASTICSEARCH_PASSWORD | changeme | Elasticsearch password | ||
|
||
If there is an existing `elasticsearch` service in the kubernetes cluster these | ||
defaults will use it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: filebeat-config | ||
namespace: kube-system | ||
labels: | ||
k8s-app: filebeat | ||
kubernetes.io/cluster-service: "true" | ||
data: | ||
filebeat.yml: |- | ||
filebeat.config: | ||
prospectors: | ||
# Mounted `filebeat-prospectors` configmap: | ||
path: ${path.config}/prospectors.d/*.yml | ||
# Reload prospectors configs as they change: | ||
reload.enabled: false | ||
modules: | ||
path: ${path.config}/modules.d/*.yml | ||
# Reload module configs as they change: | ||
reload.enabled: false | ||
|
||
processors: | ||
- add_cloud_metadata: | ||
|
||
output.elasticsearch: | ||
hosts: ['${ELASTICSEARCH_HOST:elasticsearch}:${ELASTICSEARCH_PORT:9200}'] | ||
username: ${ELASTICSEARCH_USERNAME} | ||
password: ${ELASTICSEARCH_PASSWORD} | ||
--- | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: filebeat-prospectors | ||
namespace: kube-system | ||
labels: | ||
k8s-app: filebeat | ||
kubernetes.io/cluster-service: "true" | ||
data: | ||
kubernetes.yml: |- | ||
- type: log | ||
paths: | ||
- /var/lib/docker/containers/*/*.log | ||
json.message_key: log | ||
json.keys_under_root: true | ||
processors: | ||
- add_kubernetes_metadata: | ||
in_cluster: true | ||
namespace: ${POD_NAMESPACE} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
apiVersion: extensions/v1beta1 | ||
kind: DaemonSet | ||
metadata: | ||
name: filebeat | ||
namespace: kube-system | ||
labels: | ||
k8s-app: filebeat | ||
kubernetes.io/cluster-service: "true" | ||
spec: | ||
template: | ||
metadata: | ||
labels: | ||
k8s-app: filebeat | ||
kubernetes.io/cluster-service: "true" | ||
spec: | ||
serviceAccountName: filebeat | ||
terminationGracePeriodSeconds: 30 | ||
containers: | ||
- name: filebeat | ||
image: docker.elastic.co/beats/filebeat:%VERSION% | ||
args: [ | ||
"-c", "/etc/filebeat.yml", | ||
"-e", | ||
] | ||
env: | ||
- name: ELASTICSEARCH_HOST | ||
value: elasticsearch | ||
- name: ELASTICSEARCH_PORT | ||
value: "9200" | ||
- name: ELASTICSEARCH_USERNAME | ||
value: elastic | ||
- name: ELASTICSEARCH_PASSWORD | ||
value: changeme | ||
- name: POD_NAMESPACE | ||
valueFrom: | ||
fieldRef: | ||
fieldPath: metadata.namespace | ||
securityContext: | ||
runAsUser: 0 | ||
resources: | ||
limits: | ||
memory: 200Mi | ||
requests: | ||
cpu: 100m | ||
memory: 100Mi | ||
volumeMounts: | ||
- name: config | ||
mountPath: /etc/filebeat.yml | ||
readOnly: true | ||
subPath: filebeat.yml | ||
- name: prospectors | ||
mountPath: /usr/share/filebeat/prospectors.d | ||
readOnly: true | ||
- name: data | ||
mountPath: /usr/share/filebeat/data | ||
- name: varlibdockercontainers | ||
mountPath: /var/lib/docker/containers | ||
readOnly: true | ||
volumes: | ||
- name: config | ||
configMap: | ||
defaultMode: 0600 | ||
name: filebeat-config | ||
- name: varlibdockercontainers | ||
hostPath: | ||
path: /var/lib/docker/containers | ||
- name: prospectors | ||
configMap: | ||
defaultMode: 0600 | ||
name: filebeat-prospectors | ||
- name: data | ||
emptyDir: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRoleBinding | ||
metadata: | ||
name: filebeat | ||
subjects: | ||
- kind: ServiceAccount | ||
name: filebeat | ||
namespace: kube-system | ||
roleRef: | ||
kind: ClusterRole | ||
name: filebeat | ||
apiGroup: rbac.authorization.k8s.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
apiVersion: rbac.authorization.k8s.io/v1beta1 | ||
kind: ClusterRole | ||
metadata: | ||
name: filebeat | ||
labels: | ||
k8s-app: filebeat | ||
rules: | ||
- apiGroups: [""] # "" indicates the core API group | ||
resources: | ||
- namespaces | ||
- pods | ||
verbs: | ||
- get | ||
- watch | ||
- list |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the fix