Git Product home page Git Product logo

eks-multi-container-pod-logging's Introduction

EKS Multi Container Pod Logging

This demonstration has the purpose of showing how to use multi-container Pods to export application logs to stdout on Amazon EKS, in that way a log proccessor can collect all the logs and send to a log centralizer.

This demonstration was tested in us-east-1 region

Architecture

Pre Reqs

Provision EKS cluster

We are going to use eksctl to provision our EKS cluster for this demonstration, eksctl will provision the Kubernetes master, nodes and also the VPC.

eksctl create cluster -f kubernetes-cluster-us-east-1.yaml

Now we have to configure our ~/.kube/config file in order to access our cluster using kubectl.

aws eks --region us-east-1 update-kubeconfig --name kubelogs-cluster

This will update your kube config file, now let's test if we can access our cluster.

kubectl get nodes

Creating our application Docker image and ECR repository

In this step we are going to build our application Docker image and create our ECR repository, after that we are going to push the image to the repository, so we will be able to create our application inside our Amazon EKS cluster.

aws ecr create-repository --repository-name multi-container-pod-demo

Let's build our Docker image

cd log-app && docker build -t multi-container-pod-demo .

Retrieve an authentication token and authenticate your Docker client to your registry, replace the variables <> with your information

aws ecr get-login-password --region <REGION> | docker login --username AWS --password-stdin <ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com

After the build completes, tag your image so you can push the image to ECR repository.

docker tag multi-container-pod-demo:latest <ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/multi-container-pod-demo:latest

Run the following command to push this image to your newly created AWS repository

docker push <ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/multi-container-pod-demo:latest

Kubernetes Manifests

In order to our app work we will need to replace the variable inside our Deployment manifest with our new image that we just published in the ECR.

Open log-app/eks/01-deployment.yaml and change __IMAGE_URI__ to your image URI.

containers:
      - name: python-app
        image: __IMAGE_URI__
        ports:
        - containerPort: 5000

It will look like the following

containers:
      - name: python-app
        image: <ACCOUNT_ID>.dkr.ecr.<region>.amazonaws.com/multi-container-pod-demo:latest
        ports:
        - containerPort: 5000

Let's deploy our application inside the cluster.

kubectl apply -f eks/

It will create 3 objecs, namespace, deployment and service.

Checking application logs

It's time to check if our multi-container pod works.

Let's check our Pod

kubectl get pods -n prd

Get logs of our Python application

kubectl logs po/<POD_NAME> -c python-app -n prd

It will return just the logs of the server initialization, but not the request logs because it writes in a file.

Get logs of our side car container that is responsible to output the logs to stdout.

kubectl logs po/<POD_NAME> -c sidecar -n prd -f

As you can see it show our requests logs, let this terminal open and open other terminal.

Open a new terminal and get the service URL.

kubectl get svc -n prd | awk '{print $4}'

Now execute a request to the service public URL.

curl -IL -XGET http://<SERVICE_URL>/log

It will generate random log messsages, as you can see above.

Let's once again check the logs of the python-app container.

kubectl logs po/python-app-dc4757744-szgk7 -nprd -c python-app

No new logs were generated.

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

eks-multi-container-pod-logging's People

Contributors

amazon-auto avatar lusoal avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.