- [Instructor] Once your infrastructure and your application
have been deployed successfully,
you run into your next challenge:
Are they operating correctly, have there been any errors,
are they even online?
The DevOps practices of monitoring and logging
help you answer these questions.
Let's take a look at how to do this,
specifically from a kubernetes perspective.
First up, let's tackle logging.
If your application isn't outputting logs,
it probably should.
Fellow LinkedIn Learning author and Agile admin
Ernest Mueller, wrote a great article on logging for success
that developers should read.
True story, he wrote the article after he was trying
to debug an issue with an application that I wrote,
looked at some of the good and bad things
that I'd done with my logs and the rest is history.
From a kubernetes prospective, starting out,
it's better for your applications, running in a pod,
to write your standard out.
This is because kubernetes will automatically
pick up the logs and show you anything in the log info
when you use the command kubectl logs to fetch the logs.
This is really useful when you're doing development.
Once your application is running in staging or production,
you might consider using a logging platform
like Elasticsearch in Kibana, with logs being shipped to it
from pods, using Fluentd, Filebeat or Logstash.
The architecture of this paradigm is shown here.
You would typically run a deployment
for your Elasticsearch in Kibana instance
outside of your application.
The Elasticsearch endpoint needs to be accessible
to pods in the cluster, and the Kibana instance
should be exposed as a service so that you can
see log information in the Kibana user interface.
Then, in your application deployment,
you'll want the log shipper, Fluentd, Logstash or Filebeat,
to gather log data and periodically send it
to the Elasticsearch instance.
I've included some docs to get you started
in the course exercise files, that explain this process
in a bit more detail, so take a look.
From a monitoring perspective, we have a few things
we'd like to monitor.
The node health, the health of the kubernetes cluster,
and application health and metrics.
For node and kubernetes health, the combination
of two open source projects, cAadvisor and Prometheus,
give an elegant way to monitor
your cluster and applications.
cAdvisor is an open-source resource usage collector
that was built for containers.
It auto discovers all containers in a given node
and collects CPU, memory, file system
and network usage statistics.
cAdvisor also provides the overall machine usage
by analyzing the root container on the machine.
The other project you really want to look at
is called Prometheus.
Prometheus is an open-source system monitoring
and alerting toolkit with a query language
that works really well for application-specific metrics
and can also be used from an alerting standpoint.
Prometheus was initially used
to collect application metrics,
y'know, like number of successful logins per hour,
but can also be used natively to monitor kubernetes itself,
with projects like kube-prometheus.
You can instrument your application
to save application monitoring data at a /metrics endpoint,
that Prometheus queries in a timely manner.
Prometheus and cAdvisor are typically linked to Grafana,
which is an open-source tool to visualize monitoring data.
One last note on logging and monitoring.
The architectures I've described in this section
are popular architectures today, but this space
is still pretty young and is rapidly changing.
My recommendation for logging and monitoring are as follows:
If you're going the open-source route,
read the docs for the projects.
Setting up logging and monitoring can be challenging
and there's a lot of work being done
around the user experience and setup of these tools
to make things easier.
Also, I did not cover enterprise tooling
like Datadog, Splunk or Sysdig, for example.
If you're already using these tools for your infrastructure,
take a look at what kubernetes support they have
and use them where applicable.
No point reinventing the wheel when you don't have to.