<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Josh Maxwell</title>
    <description>The latest articles on Forem by Josh Maxwell (@cctechwiz).</description>
    <link>https://forem.com/cctechwiz</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F188636%2Ff8c48261-96cf-4498-816c-d17602215f1c.png</url>
      <title>Forem: Josh Maxwell</title>
      <link>https://forem.com/cctechwiz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/cctechwiz"/>
    <language>en</language>
    <item>
      <title>Deploying Prometheus Operator via the Kubestack Catalog</title>
      <dc:creator>Josh Maxwell</dc:creator>
      <pubDate>Wed, 15 Dec 2021 13:33:17 +0000</pubDate>
      <link>https://forem.com/kubestack/deploying-prometheus-operator-via-the-kubestack-catalog-4dp</link>
      <guid>https://forem.com/kubestack/deploying-prometheus-operator-via-the-kubestack-catalog-4dp</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;This walkthrough assumes you have already followed parts &lt;a href="https://www.kubestack.com/framework/documentation/tutorial-develop-locally"&gt;one&lt;/a&gt;, &lt;a href="https://www.kubestack.com/framework/documentation/tutorial-provision-infrastructure"&gt;two&lt;/a&gt;, and &lt;a href="https://www.kubestack.com/framework/documentation/tutorial-setup-automation"&gt;three&lt;/a&gt; of the official Kubestack tutorial and at least have a local development cluster running via &lt;code&gt;kbst local apply&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In this walkthrough we will explore using the Kubestack Catalog to install a &lt;a href="https://www.kubestack.com/catalog/prometheus"&gt;Prometheus Operator&lt;/a&gt; and collect metrics from an example Go application.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Major Disclaimer:&lt;/strong&gt;&lt;br&gt;
In the interest of time and reducing technical complexity there is a very strong anti-pattern present in this walkthrough.&lt;/p&gt;

&lt;p&gt;Best practice dictates that infrastructure and application manifests be stored in separate repositories so they can be worked on and deployed independently.&lt;/p&gt;

&lt;p&gt;In this walkthrough both the Go application and the Kubestack infrastructure manifests we create will be stored in the same repository for simplicity sake while deploying to the local development environment (see the Conclusion for an explanation of how this would look following best practices).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  1 - Configure Local Development Environment
&lt;/h2&gt;

&lt;p&gt;Before we install the Prometheus Operator, we need a few additional tools installed in our local development environment in order more easily verify that our configuration is working.&lt;/p&gt;

&lt;h3&gt;
  
  
  1.1 - Install Go Locally
&lt;/h3&gt;

&lt;p&gt;Follow the instructions at &lt;a href="https://go.dev/doc/install"&gt;https://go.dev/doc/install&lt;/a&gt; to install Go for your local development environment. We need this to build our example application as well as to install another tool below.&lt;/p&gt;

&lt;h3&gt;
  
  
  1.2 - Install and Configure &lt;code&gt;kubectl&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;kubectl&lt;/code&gt; will be used primarily for two reasons. First, to verify which resources are deployed in our k8s cluster. Second, to forward ports and access resources inside the k8s cluster from our local development environment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
curl -LO "https://dl.k8s.io/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl.sha256"
echo "$(&amp;lt;kubectl.sha256) kubectl" | sha256sum --check
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
kubectl version --client
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point if &lt;code&gt;kubectl&lt;/code&gt; is successfully installed you should see output similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.3", GitCommit:"c92036820499fedefec0f847e2054d824aea6cd1", GitTreeState:"clean", BuildDate:"2021-10-27T18:41:28Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're having issues installing &lt;code&gt;kubectl&lt;/code&gt; please refer the &lt;a href="https://kubernetes.io/docs/tasks/tools/"&gt;offical documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  1.3 - Install and Configure &lt;code&gt;kind&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;kind&lt;/code&gt; (Kubernetes in Docker) will be used to export the cluster configuration file that &lt;code&gt;kubectl&lt;/code&gt; needs to access the cluster.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;GO111MODULE="on" go get sigs.k8s.io/kind@v0.11.1
kind version
kind get clusters
kind export kubeconfig --name &amp;lt;CLUSTER_NAME&amp;gt;
kubectl get namespaces
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point if &lt;code&gt;kind&lt;/code&gt; has been installed correctly and the &lt;code&gt;kubectl config&lt;/code&gt; has been exported successfully, you should see something similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME                  STATUS   AGE
default               Active   6h27m
ingress-nginx         Active   6h26m
kube-node-lease       Active   6h27m
kube-public           Active   6h27m
kube-system           Active   6h27m
local-path-storage    Active   6h27m
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you're having issues installing &lt;code&gt;kind&lt;/code&gt; please refer the &lt;a href="https://kind.sigs.k8s.io/docs/user/quick-start/"&gt;official documentation&lt;/a&gt;. Otherwise, congrats! You're ready to move on to the next part of the tutorial. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;NOTE: &lt;code&gt;kind&lt;/code&gt; is only needed for local development environments since that is how Kubestack deploys your environment locally. If you want to follow the rest of the tutorial using your cloud environment instead, you will need to download the &lt;code&gt;kubectl config&lt;/code&gt; file from that cluster and import it locally so &lt;code&gt;kubectl&lt;/code&gt; can access that cluster instead. Here are some resources about exporting that configuration file: &lt;a href="https://docs.aws.amazon.com/eks/latest/userguide/create-kubeconfig.html"&gt;EKS&lt;/a&gt;, &lt;a href="https://docs.microsoft.com/en-us/azure/aks/control-kubeconfig-access"&gt;AKS&lt;/a&gt;, &lt;a href="https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl"&gt;GKE&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  2 - Deploy an Example Go Application
&lt;/h2&gt;

&lt;p&gt;Now we're going to create an example application to emit some metrics for us to collect with Prometheus.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.1 - Create a Go Application
&lt;/h3&gt;

&lt;p&gt;Create a new GitHub repository to host your Example Go Application.&lt;/p&gt;

&lt;p&gt;Create a new Go Module in the repository with &lt;code&gt;go mod init github.com/&amp;lt;account&amp;gt;/&amp;lt;repo&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Create a main.go file in the repository with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package main

import (
    "net/http"
    "time"

    "github.com/prometheus/client_golang/prometheus"
    "github.com/prometheus/client_golang/prometheus/promauto"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)

func recordMetrics() {
    go func() {
        for {
            opsProcessed.Inc()
            time.Sleep(2 * time.Second)
        }
    }()
}

var (
    opsProcessed = promauto.NewCounter(prometheus.CounterOpts{
        Name: "app_go_prom_processed_ops_total",
        Help: "The total number of processed events",
    })
)

func main() {
    println("Starting app-go-prom on port :2112")

    recordMetrics()

    http.Handle("/metrics", promhttp.Handler())
    http.ListenAndServe(":2112", nil)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With main.go created run &lt;code&gt;go mod tidy&lt;/code&gt; to create &lt;code&gt;go.mod&lt;/code&gt; and &lt;code&gt;go.sum&lt;/code&gt; (these files should be commited to the repo).&lt;/p&gt;

&lt;h3&gt;
  
  
  2.2 - Create a Dockerfile that Runs Go Application
&lt;/h3&gt;

&lt;p&gt;Create a Dockerfile in the repository with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FROM golang:1.17-alpine

WORKDIR /app

COPY go.mod ./
COPY go.sum ./
RUN go mod download

COPY *.go ./
RUN go build -o /app-go-prom

EXPOSE 2112

CMD [ "/app-go-prom" ]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2.3 - Create a GitHub Action Pipeline to Build and Publish Docker Image
&lt;/h3&gt;

&lt;p&gt;Create a .github/workflows/docker-publish.yml file in the repository with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name: Docker Publish

on:
  push:
    branches: [ main ]
    tags: [ 'v*' ]
  pull_request:
    branches: [ main ]

env:
  REGISTRY: ghcr.io
  # github.repository as &amp;lt;account&amp;gt;/&amp;lt;repo&amp;gt;
  IMAGE_NAME: ${{ github.repository }}


jobs:
  build:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v2

      # https://github.com/docker/login-action
      - name: Log into registry ${{ env.REGISTRY }}
        if: github.event_name != 'pull_request'
        uses: docker/login-action@v1
        with:
          registry: ${{ env.REGISTRY }}
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      # https://github.com/docker/metadata-action
      - name: Extract Docker metadata
        id: meta
        uses: docker/metadata-action@v3
        with:
          images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

      # https://github.com/docker/build-push-action
      - name: Build and push Docker image
        uses: docker/build-push-action@v2
        with:
          context: .
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will build and publish a docker image to the GitHub Registry associated to the repository you created. This image can be used inside your k8s cluster.&lt;/p&gt;

&lt;p&gt;In order to trigger this to build an image tagged with &lt;code&gt;latest&lt;/code&gt; (rather than the current branch) you will need to tag the commit similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git checkout main
git pull
git tag v0.1.1
git push origin v0.1.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once the pipeline completes you should be able verify by pulling the image with &lt;code&gt;docker pull ghcr.io/&amp;lt;account&amp;gt;/&amp;lt;repo&amp;gt;:latest&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.4 - Create an Application Manifest for Kubestack to Deploy in the Cluster
&lt;/h3&gt;

&lt;p&gt;This requires two files to be created in your Kubestack IAC repository:&lt;/p&gt;

&lt;p&gt;eks_zero_applications.tf&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module "application_custom_manifests" {
  providers = {
    kustomization = kustomization.eks_zero
  }

  source  = "kbst.xyz/catalog/custom-manifests/kustomization"
  version = "0.1.0"

  configuration = {
    apps = {

      resources = [
        "${path.root}/manifests/applications/app-go-prom.yaml"
      ]

      common_labels = {
        "env" = terraform.workspace
      }
    }
    ops = {}
    loc = {}
  }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;manifests/applications/app-go-prom.yaml&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: apps/v1
kind: Deployment 
metadata:
  name: app-go-prom
  namespace: default
  labels:
    app: app-go-prom
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app-go-prom
  template:
    metadata:
      labels:
        app: app-go-prom
    spec:
      containers:
        - image: ghcr.io/&amp;lt;account&amp;gt;/&amp;lt;repo&amp;gt;:latest
          name: app-go-prom
          ports:
            - containerPort: 2112

---

apiVersion: v1
kind: Service
metadata:
  name: app-go-prom-svc
  namespace: default
  labels:
    app: app-go-prom
spec:
  selector:
    app: app-go-prom
  ports:
    - name: metrics
      port: 2112
      targetPort: 2112
      protocol: TCP
  type: LoadBalancer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With these files created you may need to ^c out of the &lt;code&gt;kbst local apply&lt;/code&gt; and run it again if watch doesn't pick up changes in custom manifest files.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.5 - Verify that the Go Application is Running and Emitting Metrics
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Note about this section:&lt;br&gt;
If you ever destroy and re-apply the local cluster you will need to run the &lt;code&gt;kind export kubeconfig --name &amp;lt;CLUSTER_NAME&amp;gt;&lt;/code&gt; command from above again to get a fresh &lt;code&gt;kubectl config&lt;/code&gt; in order for &lt;code&gt;kubectl&lt;/code&gt; to work. The cluster name will probably be the same, but if you need to find it you can always run &lt;code&gt;kind get clusters&lt;/code&gt; to figure it out.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once &lt;code&gt;kbst&lt;/code&gt; has finished applying the changes let's verify that the pod is running and that it is emitting metrics as we expect.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see output similar to the following if everything is working correctly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME                            READY   STATUS    RESTARTS   AGE
app-go-prom-6f9576879d-hvdr9    1/1     Running   0          32h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If STATUS is not "Running" there is an error. You can use &lt;code&gt;kubectl logs &amp;lt;go-app-pod-name&amp;gt;&lt;/code&gt; to check the pod logs and fix any errors.&lt;/p&gt;

&lt;p&gt;Once your Go application pod is running, lets forward the port from the associated service to our localhost and check for metrics:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get services
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With the service name in hand run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl port-forward service/app-go-prom-svc 2112
curl localhost:2112/metrics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see a bunch of metrics spit out at this point, including the one we created in our Go application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# HELP app_go_prom_processed_ops_total The total number of processed events
# TYPE app_go_prom_processed_ops_total counter
app_go_prom_processed_ops_total 25058
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run the curl command a few more times you should see our metric increasing steadily as we expect.&lt;/p&gt;

&lt;p&gt;You can stop the port forward and move on to the next section now.&lt;/p&gt;

&lt;h2&gt;
  
  
  3 - Install Prometheus Operator via the Kubestack Catalog
&lt;/h2&gt;

&lt;p&gt;Now we are going to install the Prometheus Operator &lt;a href="https://www.kubestack.com/catalog/prometheus"&gt;following the instructions&lt;/a&gt; in the Kubestack Catalog.&lt;/p&gt;

&lt;p&gt;This consists of 3 steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Adding the Prometheus Operator module to the cluster&lt;/li&gt;
&lt;li&gt;Configuring read-only access policies to monitoring targets&lt;/li&gt;
&lt;li&gt;Specifying which target services to monitor&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  3.1 - Adding the Prometheus Operator module to the cluster
&lt;/h3&gt;

&lt;p&gt;Create an eks_zero_services.tf file in the root of the repo with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module "eks_zero_prometheus" {
  providers = {
    kustomization = kustomization.eks_zero
  }

  source  = "kbst.xyz/catalog/prometheus/kustomization"
  version = "0.51.1-kbst.0"

  configuration = {
    apps = {
      additional_resources = [
        "${path.root}/manifests/services/prometheus-default-instance.yaml",
        "${path.root}/manifests/services/prometheus-service-monitors.yaml"
      ]
    }
    ops = {}
    loc = {}
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file specifies to add the &lt;code&gt;eks_zero_prometheus&lt;/code&gt; module to the &lt;code&gt;eks_zero&lt;/code&gt; kustomization provider. If you have customized the name of your provider make sure to update that here as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.2 - Create a Default Instance with permissions to monitor targets
&lt;/h3&gt;

&lt;p&gt;Now we will create first file referenced as &lt;code&gt;additional_resources&lt;/code&gt; above.&lt;/p&gt;

&lt;p&gt;Create manifests/services/prometheus-default-instance.yaml with the following contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---

apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  name: default-instance
  namespace: default
  labels:
    prometheus: default-instance
spec:
  serviceAccountName: prometheus-default-instance
  serviceMonitorSelector:
    matchLabels:
      prometheus-instance: default-instance
  resources:
    requests:
      memory: 2Gi

---

apiVersion: rbac.authorization.k8s.io/v1beta1
kind: RoleBinding
metadata:
  name: prometheus-default-instance
  namespace: default
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: prometheus-instance
subjects:
- kind: ServiceAccount
  name: prometheus-default-instance
  namespace: default

---

apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus-default-instance
  namespace: default
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file contains 3 key components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Prometheus default-instance&lt;/li&gt;
&lt;li&gt;The RoleBinding permissions&lt;/li&gt;
&lt;li&gt;The Service Account&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The default-instance is our Prometheus server that collects the metrics and serves the Prometheus UI.&lt;br&gt;
The other components are used to grant the needed permissions to read the metrics we'll specify in the next section.&lt;/p&gt;
&lt;h3&gt;
  
  
  3.3 - Specify which targets to monitor
&lt;/h3&gt;

&lt;p&gt;Finally, we will create a ServiceMonitor that ties everything together.&lt;/p&gt;

&lt;p&gt;Create the manifests/services/prometheus-service-monitors.yaml file with the following contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
  name: app-go-prom-monitor
  namespace: default
  labels:
    prometheus-instance: default-instance
spec:
  selector:
    matchLabels:
      app: app-go-prom
  endpoints:
  - port: metrics
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are 3 important pieces here to connect everything:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;metadata.labels&lt;/code&gt; here needs to exactly match the &lt;code&gt;spec.serviceMonitorSelector.matchLabels&lt;/code&gt; from the default-instance&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;spec.selector.matchLables&lt;/code&gt; here needs to exactly match the &lt;code&gt;metadata.labels&lt;/code&gt; of the Deployment from the Go application manifest&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;spec.endpoints.port&lt;/code&gt; needs to match the &lt;code&gt;spec.ports.name&lt;/code&gt; of the Service from the Go application manifest&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once all those pieces are in place you can once again run &lt;code&gt;kbst local apply&lt;/code&gt; to pickup the new manifests.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.4 - Verify all Prometheus components are Running
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;Note about this section:&lt;br&gt;
If you ever destroy and re-apply the local cluster you will need to run the &lt;code&gt;kind export kubeconfig --name &amp;lt;CLUSTER_NAME&amp;gt;&lt;/code&gt; command from above again to get a fresh &lt;code&gt;kubectl config&lt;/code&gt; in order for &lt;code&gt;kubectl&lt;/code&gt; to work. The cluster name will probably be the same, but if you need to find it you can always run &lt;code&gt;kind get clusters&lt;/code&gt; to figure it out.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Similar to how we verified our Go application was working let's check our Prometheus Operator.&lt;/p&gt;

&lt;p&gt;Once &lt;code&gt;kbst&lt;/code&gt; has finished applying the changes let's verify that the Prometheus Operator and supporting components have been successfully deployed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get all --namespace operator-prometheus
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see output similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME                                       READY   STATUS    RESTARTS   AGE
pod/prometheus-operator-775545dc6b-qffng   1/1     Running   0          40h

NAME                          TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)    AGE
service/prometheus-operator   ClusterIP   None         &amp;lt;none&amp;gt;        8080/TCP   40h

NAME                                  READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/prometheus-operator   1/1     1            1           40h

NAME                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/prometheus-operator-775545dc6b   1         1         1       40h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's check that the default-instance pod is running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see there is now a &lt;code&gt;prometheus-default-instance-0&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME                            READY   STATUS    RESTARTS   AGE
app-go-prom-6f9576879d-hvdr9    1/1     Running   0          33h
prometheus-default-instance-0   2/2     Running   0          33h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If STATUS is not "Running" there is an error. You can use &lt;code&gt;kubectl logs prometheus-default-instance-0&lt;/code&gt; to check the pod logs and fix any errors.&lt;/p&gt;

&lt;p&gt;Lastly, let's verify that our ServiceMonitor was created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get ServiceMonitors
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should see something similar to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME                  AGE
app-go-prom-monitor   33h
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't have any errors, proceed to the final section and let's verify that Prometheus is correctly collecting our metrics.&lt;/p&gt;

&lt;h2&gt;
  
  
  4 - View the Metrics in the Prometheus UI
&lt;/h2&gt;

&lt;p&gt;Now that we've got everything deployed and Running let's take one final step to verify that everything is working.&lt;/p&gt;

&lt;p&gt;Like we did before with our Go application, we now need to forward the Prometheus port to access the UI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl port-forward prometheus-default-instance-0 9090
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now from your local development environment open a web browser and navigate to &lt;code&gt;localhost:9090&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If everything has been successful to this point you should be greeted with the Prometheus dashboard.&lt;/p&gt;

&lt;p&gt;Enter the metric name into the search box that we created in our Go application; &lt;code&gt;app_go_prom_processed_ops_total&lt;/code&gt;, and click "Execute".&lt;br&gt;
You will see the metric metadata and count displayed below the search box, similar to the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app_go_prom_processed_ops_total{container="app-go-prom", endpoint="metrics", instance="10.244.1.4:2112", job="app-go-prom-svc", namespace="default", pod="app-go-prom-6f9576879d-hvdr9", service="app-go-prom-svc"}  474
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Congratulations you have successfully deploy the Prometheus Operator, created an example service emitting metrics, and configured everything to collect those metrics. That is the backbone you'll need to have visibility into the metrics of your new cluster.&lt;/p&gt;

&lt;p&gt;From here you could extend your metrics infrastructure by;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;adding additional applications / services and their associated ServiceMonitors,&lt;/li&gt;
&lt;li&gt;adding a Grafana deployment to create dashboards of your metrics,&lt;/li&gt;
&lt;li&gt;configuring an external instance of Prometheus to collect all your metrics,&lt;/li&gt;
&lt;li&gt;etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The next steps if you'd like would be to go beyond metrics and browse the &lt;a href="https://www.kubestack.com/catalog"&gt;Kubestack Catalog&lt;/a&gt; to install additional helpful services into your cluster.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Initial Disclaimer Explained:&lt;/p&gt;

&lt;p&gt;As mentioned in the beginning, we introduced a very strong anti-pattern in this walkthrough by placing our application and infrastructure manifests in the same repository.&lt;/p&gt;

&lt;p&gt;This should &lt;strong&gt;NEVER&lt;/strong&gt; be done when deploying to your real cloud infrastructure. Instead, for micro-service architectures such as this, each application would have their own code repo (in whatever language is appropriate). There would also be one additional "deployment repository" containing the Kubernetes manifests of all the applications. A service such as ArgoCD or Flux would then be configured to monitor the deployment repository and deploy changes to the Kubernetes cluster as needed when the applications are updated.&lt;/p&gt;

&lt;p&gt;The Prometheus Operator should be deployed as part of the Kubestack infrastructure. The Prometheus Instance and ServiceMonitor (all explained in more details later) should be deployed along side each application. The only exception would be if you plan to have a single Instance monitor all your services, in that case it can be deployed as part of the Kubestack infrastructure.&lt;/p&gt;

&lt;p&gt;For more information you can refer to the official documentation regarding &lt;a href="https://www.kubestack.com/framework/documentation/gitops-process#infrastructure-environments"&gt;infrastructure environments&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>gitops</category>
      <category>kubernetes</category>
      <category>devrel</category>
      <category>terraform</category>
    </item>
  </channel>
</rss>
