Helm cover deployment to external exposing example - unix1998/technical_notes GitHub Wiki

a typical Helm chart can cover all those aspectsβ€”deploying an application, exposing it internally within the cluster via a Kubernetes Service, and exposing it externally using an OpenShift Route. Helm charts are designed to encapsulate the necessary Kubernetes resources to deploy and expose an application effectively. Here's a breakdown of how each component is usually defined in a Helm chart:

1. Deployment

The Deployment resource describes the desired state for your application, such as the number of replicas, the container image to use, and the resource requirements.

Example deployment.yaml template in a Helm chart:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-app
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Release.Name }}-app
  template:
    metadata:
      labels:
        app: {{ .Release.Name }}-app
    spec:
      containers:
      - name: app
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        ports:
        - containerPort: 80
        resources:
          requests:
            cpu: {{ .Values.resources.requests.cpu }}
            memory: {{ .Values.resources.requests.memory }}
          limits:
            cpu: {{ .Values.resources.limits.cpu }}
            memory: {{ .Values.resources.limits.memory }}

2. Service

The Service resource exposes the application within the Kubernetes cluster, allowing other services and pods to communicate with it.

Example service.yaml template in a Helm chart:

apiVersion: v1
kind: Service
metadata:
  name: {{ .Release.Name }}-service
spec:
  type: ClusterIP
  ports:
  - port: 80
    targetPort: 80
  selector:
    app: {{ .Release.Name }}-app

3. Route (OpenShift Specific)

The Route resource in OpenShift exposes the application to the outside world by providing an external URL.

Example route.yaml template in a Helm chart:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: {{ .Release.Name }}-route
spec:
  to:
    kind: Service
    name: {{ .Release.Name }}-service
  port:
    targetPort: 80

Combining Everything in Helm Chart

Your Helm chart will typically have a structure like this:

my-chart/
  β”œβ”€β”€ Chart.yaml
  β”œβ”€β”€ values.yaml
  β”œβ”€β”€ templates/
  β”‚   β”œβ”€β”€ deployment.yaml
  β”‚   β”œβ”€β”€ service.yaml
  β”‚   └── route.yaml
  └── ...

Chart.yaml: Contains metadata about the chart (name, version, etc.).

values.yaml: Contains default values for the templates (replica count, image details, resource limits, etc.).

Example values.yaml:

replicaCount: 3
image:
  repository: my-app
  tag: latest
resources:
  requests:
    cpu: "100m"
    memory: "128Mi"
  limits:
    cpu: "500m"
    memory: "512Mi"

Installing the Helm Chart

To deploy the application, expose it as a service, and create a route, you would run:

helm install my-release my-chart

This command:

  • Uses the Helm chart (my-chart) to create the deployment, service, and route.
  • The my-release is the release name which Helm uses to track this deployment.

Summary

  • Deployment: Describes the application's desired state (e.g., container image, replicas).
  • Service: Exposes the application within the cluster.
  • Route: Exposes the application to the outside world (OpenShift specific).

These resources are typically defined in the templates of a Helm chart, and Helm handles the templating and deployment, making it easy to manage Kubernetes applications.