Skip to content

Add EKS example #41

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

Merged
merged 1 commit into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/run-integ-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $rootdir/bin/start-agent.sh
###################################

echo "Waiting for agent to start."
tail -f $tempfile | sed '/Output \[cloudwatchlogs\] buffer/ q'
tail -f $tempfile | sed '/Loaded outputs: cloudwatchlogs/ q'
containerId=$(docker ps -q)
echo "Agent started in container: $containerId."

Expand All @@ -41,6 +41,7 @@ status_code=$?
# Cleanup
###################################

cat $tempfile
docker stop $containerId
rm -rf $tempfile
rm -rf ./.aws/credentials
Expand Down
13 changes: 13 additions & 0 deletions examples/eks/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:10.16.0-alpine AS base
RUN mkdir -p /app/src
WORKDIR /app/src

COPY package.json ./
# install packages but copy the local version of the package in directly
RUN npm i && rm -rf node_modules/aws-embedded-metrics
COPY node_modules/aws-embedded-metrics ./node_modules/aws-embedded-metrics

# copy the source files over
COPY . .

CMD [ "node", "app" ]
35 changes: 35 additions & 0 deletions examples/eks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Running Locally

```
npm i && npm run serve-local
```

# Deploying

1. Build and push the docker image. You will want to use your own Dockerhub repository.
```
docker login
docker build . -t jaredcnance/eks-demo:latest
docker push jaredcnance/eks-demo
```

2. Apply the configuration to your cluster.
```
kubectl apply -f kubernetes/deployment.yaml
kubectl apply -f kubernetes/service.yaml
kubectl get deployment eks-demo
```

3. To test, naviagate to your ELB endpoint for the cluster:

```
curl http://<endpoint>.<region>.elb.amazonaws.com/ping
```

4. To update, re-build, push changes and delete the running pod.

```
docker build . -t jaredcnance/eks-demo:latest
docker push jaredcnance/eks-demo
kubectl delete pod ...
```
24 changes: 24 additions & 0 deletions examples/eks/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const Koa = require('koa');
const app = new Koa();

const { metricScope, Configuration, Unit } = require('aws-embedded-metrics');

Configuration.serviceName = 'EKS-Demo';
Configuration.serviceType = 'AWS::EKS::Cluster';
Configuration.logStreamName = process.env.HOSTNAME;

app.use(
metricScope(metrics => async (ctx, next) => {
const start = Date.now();

await next();

ctx.body = `Hello World ... ${ctx.method} ${ctx.url}\n`;

metrics.setProperty('Method', ctx.method);
metrics.setProperty('Url', ctx.url);
metrics.putMetric('ProcessingTime', Date.now() - start, Unit.Milliseconds);
}),
);

app.listen(3000);
18 changes: 18 additions & 0 deletions examples/eks/cwagent-configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
data:
# Any changes here must not break the JSON format
cwagentconfig.json: |
{
"agent": {
"omit_hostname": true
},
"logs": {
"metrics_collected": {
"emf": { }
}
}
}
kind: ConfigMap
metadata:
name: cw-agent-config
namespace: default
56 changes: 56 additions & 0 deletions examples/eks/kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: eks-demo
labels:
app: eks-demo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: eks-demo
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: eks-demo
spec:
containers:
- image: jaredcnance/eks-demo:latest
imagePullPolicy: Always
name: eks-demo
ports:
- containerPort: 3000
protocol: TCP
env:
- name: AWS_EMF_AGENT_ENDPOINT
value: "tcp://127.0.0.1:25888"
- name: AWS_EMF_ENABLE_DEBUG_LOGGING
value: "true"
- image: amazon/cloudwatch-agent:latest
name: cloudwatch-agent
imagePullPolicy: Always
resources:
limits:
cpu: 200m
memory: 100Mi
requests:
cpu: 200m
memory: 100Mi
volumeMounts:
- name: cwagentconfig
mountPath: /etc/cwagentconfig
ports:
- protocol: TCP
hostPort: 25888
containerPort: 25888
volumes:
- name: cwagentconfig
configMap:
name: cw-agent-config

13 changes: 13 additions & 0 deletions examples/eks/kubernetes/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

apiVersion: v1
kind: Service
metadata:
name: eks-demo
spec:
selector:
app: eks-demo
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 3000
Loading