🐶
Kubernetes

Kubernetes /healthz Health Check Origin Explained

By Jan on 01/14/2025

Discover the origins and reasons behind the /healthz convention for application health checks in Kubernetes.

Kubernetes /healthz Health Check Origin Explained

Table of Contents

Introduction

This guide provides a step-by-step approach to deploying Apache Solr on a Kubernetes cluster using a YAML configuration file. We will define a deployment for Solr, specify the desired image and resource limits, and configure environment variables. To make Solr accessible, we will create a service and expose it within the cluster. Finally, we will deploy the configuration to Kubernetes and verify access to the Solr dashboard.

Step-by-Step Guide

  1. Define your Solr deployment:

    apiVersion: apps/v1
    kind: Deployment
    # ... rest of your deployment configuration
  2. Specify the Solr image and resources:

    spec:
      template:
        spec:
          containers:
          - name: solr
            image: solr:8.11.2
            resources:
              limits:
                memory: "1Gi"
                cpu: "1"
  3. Configure Solr environment variables:

            env:
            - name: SOLR_HOME
              value: /opt/solr/server
            - name: SOLR_OPTS
              value: -Dsolr.log.dir=/var/solr/logs
  4. Create a Service to expose Solr:

    apiVersion: v1
    kind: Service
    # ... service configuration
    spec:
      selector:
        app: solr
      ports:
      - protocol: TCP
        port: 8983
        targetPort: 8983
  5. Deploy to Kubernetes:

    kubectl apply -f your-solr-deployment.yaml
  6. Access the Solr dashboard:

    • Find the service IP and port: kubectl get svc solr
    • Access the dashboard at http://<service-ip>:<port>/solr

Code Example

This code describes how to deploy a single-replica Solr instance on a Kubernetes cluster. It defines a Deployment that uses the solr:8.11.2 image and sets resource limits, environment variables, and a service on port 8983. A Service is then created to expose the Solr deployment, allowing access to the Solr dashboard. The deployment and service are applied to the cluster using kubectl. Finally, instructions are provided for accessing the Solr dashboard using the service IP and port.

This example demonstrates deploying Solr on Kubernetes using a Deployment and Service.

1. Define the Solr Deployment (solr-deployment.yaml):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: solr
spec:
  replicas: 1
  selector:
    matchLabels:
      app: solr
  template:
    metadata:
      labels:
        app: solr
    spec:
      containers:
      - name: solr
        image: solr:8.11.2
        resources:
          limits:
            memory: "1Gi"
            cpu: "1"
        env:
        - name: SOLR_HOME
          value: /opt/solr/server
        - name: SOLR_OPTS
          value: -Dsolr.log.dir=/var/solr/logs
        ports:
        - containerPort: 8983

2. Create the Solr Service (solr-service.yaml):

apiVersion: v1
kind: Service
metadata:
  name: solr
spec:
  selector:
    app: solr
  ports:
  - protocol: TCP
    port: 8983
    targetPort: 8983

3. Deploy to Kubernetes:

kubectl apply -f solr-deployment.yaml
kubectl apply -f solr-service.yaml

4. Access the Solr Dashboard:

kubectl get svc solr

This command will output the service details, including the service IP and port. Use these details to access the Solr dashboard:

http://<service-ip>:<port>/solr

Explanation:

  • Deployment: Defines a deployment named "solr" with one replica. It uses the solr:8.11.2 image and sets resource limits. Environment variables SOLR_HOME and SOLR_OPTS configure Solr's home directory and logging.
  • Service: Exposes the Solr deployment on port 8983. It uses a selector to target pods with the label "app: solr".
  • Deployment Commands: Apply the deployment and service configurations to the Kubernetes cluster.
  • Accessing the Dashboard: Retrieve the service IP and port using kubectl get svc solr and access the dashboard using the provided URL.

This example provides a basic Solr deployment. You can customize it further by adding features like persistent volumes for data persistence, ingress for external access, and more.

Additional Notes

General:

  • Image Version: Consider using a specific Solr version tag (e.g., solr:8.11.2) instead of latest for better control and reproducibility.
  • Resource Limits: Adjust memory and cpu limits based on your expected workload and cluster resources.
  • Persistence: This example doesn't include persistent storage. For production, use PersistentVolumes to store Solr data and ensure data durability across pod restarts.
  • Replicas: For high availability, increase replicas in the Deployment to have multiple Solr instances. Consider using a StatefulSet for managing stateful data in a clustered Solr setup.
  • Security: This example doesn't cover authentication or authorization. For production, implement appropriate security measures to protect your Solr instance.

Deployment:

  • Liveness and Readiness Probes: Add liveness and readiness probes to your Deployment to monitor the health of your Solr pods and ensure they are ready to serve traffic.
  • Init Containers: Use init containers to perform tasks like pre-loading data or configuring Solr before the main container starts.

Service:

  • Service Type: Consider using a different Service type (e.g., LoadBalancer) if you need to expose Solr outside the cluster.
  • Ingress: For external access, create an Ingress resource to route traffic to your Solr Service.

Additional Considerations:

  • Monitoring: Set up monitoring and logging for your Solr deployment to track performance and identify issues.
  • Scaling: Plan for scaling your Solr deployment horizontally (adding more pods) or vertically (increasing resources per pod) as your data and traffic grow.
  • Configuration Management: Use a configuration management tool like ConfigMaps or Secrets to manage Solr configuration files and sensitive data separately from your deployment files.

Customization:

  • Solr Configuration: This example uses default Solr settings. Customize your Solr configuration by mounting configuration files as volumes or using environment variables.
  • Plugins: Install and configure Solr plugins to extend its functionality.

By considering these notes, you can create a more robust, secure, and scalable Solr deployment on Kubernetes.

Summary

This document outlines the steps to deploy Apache Solr on a Kubernetes cluster using a YAML configuration file.

Here's a breakdown of the process:

  1. Define Deployment: A Kubernetes Deployment is used to manage the Solr application.
  2. Specify Image & Resources: The deployment specifies the desired Solr Docker image (solr:8.11.2 in this case) and allocates CPU and memory resources for the container.
  3. Configure Environment: Important Solr settings are defined using environment variables within the deployment. This includes SOLR_HOME (Solr's installation directory) and SOLR_OPTS (for customizing Solr's behavior, like setting the log directory).
  4. Create Service: A Kubernetes Service exposes Solr to the network. This allows access to the Solr dashboard from outside the cluster. The service maps the Solr port (8983) to the same port on the service.
  5. Deploy: The kubectl apply command deploys the configuration defined in the YAML file to the Kubernetes cluster.
  6. Access Dashboard: After deployment, you can find the service's IP address and port using kubectl get svc solr. Access the Solr dashboard in your web browser using this information (e.g., http://<service-ip>:<port>/solr).

This approach provides a structured and repeatable way to deploy and manage Solr on Kubernetes, ensuring that your search service is scalable and highly available.

Conclusion

This guide provides a comprehensive overview of deploying a single-instance Apache Solr on a Kubernetes cluster. By leveraging Kubernetes Deployments and Services, we can ensure the application's scalability and accessibility. The provided YAML configurations offer a starting point for defining the Solr deployment, specifying resource limits, and exposing the service. Remember to tailor these configurations to your specific needs, considering factors like persistent storage, security, and resource allocation. With this foundation, you can effectively deploy and manage your Solr instance within a Kubernetes environment.

References

Were You Able to Follow the Instructions?

😍Love it!
😊Yes
😐Meh-gical
😞No
🤮Clickbait