{"id":1034,"date":"2024-11-06T23:42:52","date_gmt":"2024-11-07T06:42:52","guid":{"rendered":"http:\/\/184.72.63.26\/?p=1034"},"modified":"2024-11-28T22:43:12","modified_gmt":"2024-11-29T05:43:12","slug":"log-analytics-and-monitoring-for-google-kubernetes-engine-gke-with-hipster-shop","status":"publish","type":"post","link":"https:\/\/www.wallacel.com\/index.php\/2024\/11\/06\/log-analytics-and-monitoring-for-google-kubernetes-engine-gke-with-hipster-shop\/","title":{"rendered":"Log Analytics and Monitoring for Google Kubernetes Engine (GKE) with Hipster Shop"},"content":{"rendered":"\n<p>This blog will guide you through setting up log analytics, monitoring and alert for a Google Kubernetes Engine (GKE) cluster using the Hipster Shop Observability Demo Application as reference.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Introduction to Kubernetes Monitoring and Log Analytics<\/strong><\/h3>\n\n\n\n<p>Monitoring and log analytics in Kubernetes are essential for ensuring:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Performance<\/strong>: Detecting latency issues, CPU bottlenecks (e.g. throttling), and slowdowns.<\/li>\n\n\n\n<li><strong>Reliability<\/strong>: Catching errors and failures before they impact end-users.<\/li>\n\n\n\n<li><strong>Security<\/strong>: Identifying security anomalies like unauthorized access.<\/li>\n<\/ul>\n\n\n\n<p>Effective monitoring and logging provide insights into application health, inter-service communication, and resource usage, enabling faster troubleshooting and optimization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Why Use Hipster Shop as a Demo?<\/strong><\/h3>\n\n\n\n<p><strong>Hipster Shop<\/strong> is a microservices-based application designed by Google, simulating an e-commerce platform. It consists of several services (e.g., <code>emailservice<\/code>, <code>checkoutservice<\/code>, <code>cartservice<\/code>, etc.), making it an ideal reference for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Microservices Monitoring<\/strong>: Hipster Shop\u2019s architecture mirrors real-world applications with interdependent services.<\/li>\n\n\n\n<li><strong>Load Testing<\/strong>: The demo includes a <code>loadgenerator<\/code> to simulate realistic traffic.<\/li>\n\n\n\n<li><strong>Dynatrace Integration<\/strong>: The demo supports full observability with tools like Dynatrace to monitor, analyze, and troubleshoot services.<\/li>\n<\/ul>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6a00580256d77&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6a00580256d77\" class=\"wp-block-image size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"454\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/hipster-shop-1024x454-1.png\" alt=\"\" class=\"wp-image-1090\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/hipster-shop-1024x454-1.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/hipster-shop-1024x454-1-300x133.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/hipster-shop-1024x454-1-768x341.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\taria-label=\"Enlarge\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.imageButtonRight\"\n\t\t\tdata-wp-style--top=\"state.imageButtonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><figcaption class=\"wp-element-caption\"><em>Hipster shop demo application&#8217;s microservice architecture<\/em><\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Setting Up Google Kubernetes Engine (GKE)<\/strong><\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Prerequisite:<\/h4>\n\n\n\n<p>Ensure the following tools are installed on your machine:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>kubectl<\/li>\n\n\n\n<li>gcloud<\/li>\n\n\n\n<li>git<\/li>\n\n\n\n<li>helm<\/li>\n\n\n\n<li>jq<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Create a GKE Cluster<\/h4>\n\n\n\n<p>Start by creating a GKE cluster via the Google Cloud Console or CLI:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><code>gcloud container clusters create hipster-shop-cluster \\\n    --zone us-west1-a \\\n    --num-nodes 2 \\\n    --machine-type e2-standard-8\n<\/code><\/code><\/pre>\n\n\n\n<p>This sets up a Kubernetes cluster with two nodes, each configured for microservices deployment.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"634\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-1024x634.png\" alt=\"\" class=\"wp-image-1037\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-1024x634.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-300x186.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-768x475.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image.png 1071w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Deploying Hipster Shop on GKE<\/strong><\/h3>\n\n\n\n<p><strong>Clone the Hipster Shop Repository<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><code>https:\/\/github.com\/GoogleCloudPlatform\/microservices-demo.git<\/code><\/code><\/pre>\n\n\n\n<p><strong>Deploy Hipster Shop to GKE<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><code>kubectl apply -f .\/release\/kubernetes-manifests.yaml <span style=\"font-size: var(--wp--preset--font-size--medium);\">-n hipster-shop<\/span><\/code><\/code><\/pre>\n\n\n\n<p>This command deploys each microservice along with their configurations, such as services and deployments, into the GKE cluster.<\/p>\n\n\n\n<p><strong>Verify the pods are ready<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><code>kubectl get pods <span style=\"font-size: var(--wp--preset--font-size--medium);\">-n hipster-shop<\/span><\/code><\/code><\/pre>\n\n\n\n<p>After a few minutes, you should see the pods are in a running state.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><code>NAME                                     READY   STATUS    RESTARTS   AGE\nadservice-86d5fd9c56-tprp6               1\/1     Running   0          75s\ncartservice-6bb7677d47-lv25q             1\/1     Running   0          78s\ncheckoutservice-64fd47cdfb-ldm8w         1\/1     Running   0          81s\ncurrencyservice-8587877797-q24bg         1\/1     Running   0          77s\nemailservice-78d967474f-bdl2k            1\/1     Running   0          82s\nfrontend-84fb499859-f66dw                1\/1     Running   0          79s\npaymentservice-c5fb8bfb6-6cvs8           1\/1     Running   0          79s\nproductcatalogservice-64cffd9d98-7vdhl   1\/1     Running   0          78s\nrecommendationservice-549cc495d-285w5    1\/1     Running   0          80s\nredis-cart-867cd85fd4-l6zkm              2\/2     Running   0          76s\nshippingservice-685bc78f7b-jjg9z         1\/1     Running   0          77s<\/code><\/code><\/pre>\n\n\n\n<p><strong>Expose the Frontend<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><code>helm upgrade --install ingress-nginx ingress-nginx  --repo https:\/\/kubernetes.github.io\/ingress-nginx  --namespace ingress-nginx --create-namespace\n<\/code><\/code><\/pre>\n\n\n\n<p>This command installs the NGINX Ingress Controller as a load balancer to exposes the frontend of the Hipster Shop application.<\/p>\n\n\n\n<p><strong>Get the URL to your deployed Hipster Shop<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"><code>kubectl get svc ingress-nginx-controller -n ingress-nginx -ojson | jq -j '.status.loadBalancer.ingress[].ip'\n<\/code><\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"881\" height=\"868\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/hipster-shop-1.png\" alt=\"\" class=\"wp-image-1047\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/hipster-shop-1.png 881w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/hipster-shop-1-300x296.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/hipster-shop-1-768x757.png 768w\" sizes=\"auto, (max-width: 881px) 100vw, 881px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Implementing Log Analytics in GKE<\/strong><\/h3>\n\n\n\n<p>There are two ways you can enable Log Analytics to get insights into your GKE cluster. One way is to upgrade an existing bucket. The other is to create a new log bucket with Log Analytics enabled.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Create a new log bucket<\/h4>\n\n\n\n<p>You can configure Cloud Logging to create a new log bucket with Log Analytics enabled. <\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Navigate to <strong>Logging, <\/strong>then click <strong>Logs Storage<\/strong> in the Cloud Console<\/li>\n\n\n\n<li>Click <strong>CREATE LOG BUCKET<\/strong> at top, name the log bucket as <strong>hipstershop_log<\/strong><\/li>\n\n\n\n<li>Check both <strong>Upgrade to use Log Analytics<\/strong> and <strong>Create a new BigQuery dataset that links to this bucket<\/strong><\/li>\n\n\n\n<li>Type in a dataset name like <strong>hipstershop_dataset<\/strong><\/li>\n\n\n\n<li>Click <strong>Create bucket<\/strong> to create the log bucket<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"843\" height=\"782\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-1.png\" alt=\"\" class=\"wp-image-1049\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-1.png 843w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-1-300x278.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-1-768x712.png 768w\" sizes=\"auto, (max-width: 843px) 100vw, 843px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Write to the new log bucket<\/h4>\n\n\n\n<p>To write logs from our GKE cluster to the new log bucket, you need to create a <strong>log sink<\/strong> and specify the log destination and setup a log filter for logging the gke cluster.<\/p>\n\n\n\n<p>Navigate to <strong>Logging, <\/strong>then click <strong>Logs Explorer<\/strong> in the Cloud Console, and enable <strong>Show query <\/strong>on the top right and add the following filter.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">resource.type=\"k8s_container\"<\/code><\/pre>\n\n\n\n<p>Click on <strong>Actions<\/strong> and then <strong>Create sink<\/strong>. <\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Name the sink as <strong>hipstershop_sink<\/strong><\/li>\n\n\n\n<li>Select <strong>Logging bucket<\/strong> in the sink service, then choose <strong>hipstershop_log<\/strong> bucket<\/li>\n\n\n\n<li>Click <strong>CREATE SINK<\/strong><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"938\" height=\"773\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-2.png\" alt=\"\" class=\"wp-image-1050\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-2.png 938w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-2-300x247.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-2-768x633.png 768w\" sizes=\"auto, (max-width: 938px) 100vw, 938px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Perform analytics on logs<\/h4>\n\n\n\n<p>Now we can perform analytics on logs stored in the hipster shop log bucket by running our own query in <strong>Log Analytics<\/strong>. In the&nbsp;<strong>Log views<\/strong>&nbsp;list, select the <strong>hipstershop_log._AllLogs<\/strong>, and then select&nbsp;<strong>Query<\/strong>. The&nbsp;<strong>Query<\/strong>&nbsp;pane is populated with a default query, which includes the log view that is queried.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"242\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-4-1024x242.png\" alt=\"\" class=\"wp-image-1052\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-4-1024x242.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-4-300x71.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-4-768x181.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-4.png 1076w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>To find the min, max and average latency (in ms) for the frontend service:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">SELECT hour,\nMIN(took_ms) AS min,\nMAX(took_ms) AS max,\nAVG(took_ms) AS avg\nFROM ( SELECT\n  FORMAT_TIMESTAMP(\"%H\", timestamp) AS hour,\n  CAST( JSON_VALUE(json_payload,\n      '$.\"http.resp.took_ms\"') AS INT64 ) AS took_ms\nFROM `hipster-shop-440423.global.hipstershop_log._AllLogs`\nWHERE\n  json_payload IS NOT NULL\n  AND SEARCH(labels,\"frontend\")\n  AND JSON_VALUE(json_payload.message) = \"request complete\"\nORDER BY took_ms DESC, timestamp ASC )\nGROUP BY 1<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"946\" height=\"559\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-7.png\" alt=\"\" class=\"wp-image-1056\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-7.png 946w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-7-300x177.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-7-768x454.png 768w\" sizes=\"auto, (max-width: 946px) 100vw, 946px\" \/><\/figure>\n\n\n\n<p><strong>To find all sessions with shopping cart checkout:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"sql\" class=\"language-sql\">SELECT\n JSON_VALUE(json_payload.session) as session_id ,COUNT(*) as count\nFROM `hipster-shop-440423.global.hipstershop_log._AllLogs`\nWHERE\n JSON_VALUE(json_payload['http.req.method']) = \"POST\"\n AND JSON_VALUE(json_payload['http.req.path']) = \"\/cart\/checkout\"\nGROUP BY\n JSON_VALUE(json_payload.session)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"609\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-9.png\" alt=\"\" class=\"wp-image-1059\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-9.png 836w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-9-300x219.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-9-768x559.png 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Monitoring your GKE cluster health with Dashboards and Alert<\/strong><\/h3>\n\n\n\n<p>To effectively monitor your GKE cluster and observe how it handles the load generated by the Hipster Shop demo application, you can set up a custom Google Cloud Monitoring dashboard to display key metrics such as <strong>CPU Request Utilization<\/strong> or <strong>Memory Limit Utilization<\/strong>, giving you insights into resource usage. For instance, we want to monitor the CPU utilization because if it consistently nears or exceeds 100%, our cluster may be at risk of CPU throttling, which can degrade application performance.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Create a Custom Dashboard to monitor your pods<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Go to the Google Cloud Console and open <strong>Monitoring<\/strong><\/li>\n\n\n\n<li>Select <strong>Metrics Explorer<\/strong> from the left menu and click on <strong>Select a metric<\/strong><\/li>\n\n\n\n<li>Select&nbsp;<strong>Kubernetes Container &gt; Popular Metrics &gt; CPU request utilization<\/strong><\/li>\n\n\n\n<li>Click <strong>Apply<\/strong><\/li>\n\n\n\n<li>Now click the&nbsp;<strong>Save Chart<\/strong>&nbsp;button and name the dashboard as <strong>K8s Container Dashboard<\/strong><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"551\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/gcp-dashboard-1024x551.png\" alt=\"\" class=\"wp-image-1093\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/gcp-dashboard-1024x551.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/gcp-dashboard-300x161.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/gcp-dashboard-768x413.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/gcp-dashboard.png 1529w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Create an Alert to Identify Incident<\/h4>\n\n\n\n<p>We&nbsp;will create an alert policy to detect high CPU utilization among the containers and send notifications when the CPU usage exceeds a specific threshold, indicating potential resource constraints. Then we can use the dashboard to identify and respond to the incident.<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>In the Cloud Console, navigate to&nbsp;<strong>Monitoring &gt; Alerting<\/strong><\/li>\n\n\n\n<li>Click&nbsp;<strong>+ Create Policy<\/strong><\/li>\n\n\n\n<li>Click on&nbsp;<strong>Select a metric<\/strong>&nbsp;dropdown<\/li>\n\n\n\n<li>Uncheck the&nbsp;<strong>Active<\/strong>&nbsp;option<\/li>\n\n\n\n<li>Click on&nbsp;<strong>Kubernetes Container &gt; Container<\/strong>-&gt;<strong>CPU request utilization<\/strong>, then click <strong>Apply<\/strong><\/li>\n\n\n\n<li>Set&nbsp;<strong>Rolling windows<\/strong>&nbsp;to 1 min, click <strong>Next<\/strong><\/li>\n\n\n\n<li>Set Threshold position to&nbsp;<strong>Above Threshold<\/strong><\/li>\n\n\n\n<li>Choose <strong>Threshold<\/strong> and define a <strong>Threshold value<\/strong> (e.g., 0.8 for 80% utilization)<\/li>\n\n\n\n<li>Under <strong>Advanced Options<\/strong>, set <strong>Retest window<\/strong> to <strong>5 min<\/strong>. By using a retest window, you can reduce the number of unnecessary alerts that might occur due to temporary anomalies in metrics. Click <strong>Next<\/strong><\/li>\n\n\n\n<li><strong>Configure Notification Channels<\/strong> &#8211; Choose how you&#8217;d like to be notified (e.g., email, Slack, SMS), name the alert policy and then click C<strong>reate Policy<\/strong><\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"574\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-11-1024x574.png\" alt=\"\" class=\"wp-image-1064\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-11-1024x574.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-11-300x168.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-11-768x430.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-11.png 1271w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Monitor and Respond<\/h4>\n\n\n\n<p>With the dashboard and alert policy in place, you can now:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>View real-time insights<\/strong> on CPU usage and active users.<\/li>\n\n\n\n<li><strong>Receive alerts<\/strong> when CPU usage exceeds the set threshold, allowing you to investigate and address potential issues before they impact the application\u2019s performance.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"963\" height=\"797\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-12.png\" alt=\"\" class=\"wp-image-1065\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-12.png 963w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-12-300x248.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-12-768x636.png 768w\" sizes=\"auto, (max-width: 963px) 100vw, 963px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7. Load Testing and Stress Analysis<\/strong><\/h3>\n\n\n\n<p>We will use the <code>loadgenerator<\/code> included in the Hipster Shop demo application to simulate some user traffic.<\/p>\n\n\n\n<p><strong>Update Kubernetes Configuration for the Loadgenerator<\/strong><\/p>\n\n\n\n<p>In <code>k8s-manifest.yaml<\/code>, you can adjust how the loadgenerator runs in your cluster:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Concurrency and Duration<\/strong>: Define how many users and how long they should interact with the app.<\/li>\n\n\n\n<li><strong>Resource Limits<\/strong>: Adjust resource requests\/limits to control how much CPU and memory the loadgenerator uses.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"yaml\" class=\"language-yaml\">apiVersion: batch\/v1\nkind: CronJob\nmetadata:\n  name: loadgeneratorservice\n  labels:\n    app.kubernetes.io\/component: loadgenerator\n    app.kubernetes.io\/part-of: hipster-shop\n    app.kubernetes.io\/name: loadgenerator\nspec:\n  schedule: \"*\/15 * * * *\"  # Runs every 15 minutes\n  jobTemplate:\n    spec:\n      template:\n        spec:\n          restartPolicy: OnFailure\n          containers:\n            - name: loadgenerator\n              image: loadgenerator-image\n              args: [\"-u\", \"50\", \"-d\", \"10m\"]<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Schedule<\/strong>: <code>\"*\/15 * * * *\"<\/code> triggers the CronJob every 15 minutes.<\/li>\n\n\n\n<li><strong>Number of virtual users<\/strong> (<code>-u <\/code>50) is set to 50. For heavier load, increase this value.<\/li>\n\n\n\n<li><strong>Duration<\/strong>: Set the duration (<code>-d 10m<\/code>) in the <code>args<\/code> to 10 minutes to allow a short break between runs. This prevents overlap between consecutive jobs and allows each job to finish before the next one starts<\/li>\n<\/ul>\n\n\n\n<p>After configuring, you can deploy the modified loadgenerator to your GKE cluster:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">kubectl apply -f k8s-manifest.yaml -n hipster-shop<\/code><\/pre>\n\n\n\n<p>This will apply a load to the web store and after a while we will start receiving alert notifications. We can open the incident summary and respond to it by clicking on <strong>Acknowledge Incident<\/strong>. The incident status now shows Acknowledged, but that doesn&#8217;t solve the problem. In reality, you need to fix the root cause of the problem.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"444\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-13-1024x444.png\" alt=\"\" class=\"wp-image-1066\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-13-1024x444.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-13-300x130.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-13-768x333.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-13.png 1258w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"680\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-14-1024x680.png\" alt=\"\" class=\"wp-image-1067\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-14-1024x680.png 1024w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-14-300x199.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-14-768x510.png 768w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-14.png 1290w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"993\" height=\"743\" src=\"http:\/\/184.72.63.26\/wp-content\/uploads\/2024\/11\/image-15.png\" alt=\"\" class=\"wp-image-1068\" srcset=\"https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-15.png 993w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-15-300x224.png 300w, https:\/\/www.wallacel.com\/wp-content\/uploads\/2024\/11\/image-15-768x575.png 768w\" sizes=\"auto, (max-width: 993px) 100vw, 993px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>10. Conclusion<\/strong><\/h3>\n\n\n\n<p>Monitoring and log analytics are essential for managing complex microservices applications in Kubernetes. Using <strong>Google Log Analytics and Monitoring<\/strong>, you can ensure comprehensive observability for your GKE cluster and container application. But monitoring doesn\u2019t stop at metrics; actionable insights into logs and traces help you detect and resolve issues faster, ensuring your applications are always running smoothly. <\/p>\n\n\n\n<p>Thank you for reading my blog and I hope you like it!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This blog will guide you through setting up log analytics, monitoring and alert for a Google Kubernetes Engine (GKE) cluster using the Hipster Shop Observability Demo Application as reference. 1. Introduction to Kubernetes Monitoring and Log Analytics Monitoring and log analytics in Kubernetes are essential for ensuring: Effective monitoring and logging provide insights into application [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1076,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[69],"tags":[66,68,23,67],"class_list":["post-1034","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gcp","tag-gke","tag-hipster-shop","tag-kubernetes","tag-log-analytics"],"_links":{"self":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/1034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/comments?post=1034"}],"version-history":[{"count":32,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/1034\/revisions"}],"predecessor-version":[{"id":1126,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/posts\/1034\/revisions\/1126"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/media\/1076"}],"wp:attachment":[{"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/media?parent=1034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/categories?post=1034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wallacel.com\/index.php\/wp-json\/wp\/v2\/tags?post=1034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}