-1

Does the default helm chart actually run and do something I can observe?

I've tried running it (the default helm chart) and it does run; So, what does it do?

To recreate the problem I'm asking about, do the following:

helm create helm-it                 # Create a helm chart (the default)
helm install helm-it ./helm-it      # Run it
helm list                           # See it running
helm get manifest helm-it           # See the manifest (YAML) that is running (I think)

By examining the manifest (using helm get manifest helm-it), I can see how it's configured. The important bit is:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: helm-it
  labels:
    helm.sh/chart: helm-it-0.1.0
    app.kubernetes.io/name: helm-it
    app.kubernetes.io/instance: helm-it
    app.kubernetes.io/version: "1.16.0"
    app.kubernetes.io/managed-by: Helm
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: helm-it
      app.kubernetes.io/instance: helm-it
  template:
    metadata:
      labels:
        app.kubernetes.io/name: helm-it
        app.kubernetes.io/instance: helm-it
    spec:
      serviceAccountName: helm-it
      securityContext:
        {}
      containers:
        - name: helm-it
          securityContext:
            {}
          image: "nginx:1.16.0"
          imagePullPolicy: IfNotPresent
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            {}

It seems to be running nginx on port 80 but when trying to access it using curl, I got an error (see output below).

curl http://localhost:80
curl: (7) Failed to connect to localhost port 80: Connection refused

I looked for a solution

Why I care

The reason I'm asking is because I'm trying to convert a k8s yaml file into a helm chart and want to know what I'm starting with to know what I can delete and what I need to add. I found this link:

just drop that file under templates/ and add a Chart.yml.

which I tried but it didn't work.

PatS
  • 8,833
  • 12
  • 57
  • 100

1 Answers1

0

The templates created by the helm create command run Nginx as a stateless application. I found this in the book Learning Helm, by Matt Butcher, Matt Farina, Josh Dolitsky on page 67. Available in OReilly online books and Google Books.

To access the NGINX application, you might need to forward data from your host to the K8S cluster.

When performing the helm install it gives this output:

helm install myapp anvil
NAME: myapp
LAST DEPLOYED: Fri Apr 23 12:23:46 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
NOTES:
1. Get the application URL by running these commands:
  export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=anvil,app.kubernetes.io/instance
=myapp" -o jsonpath="{.items[0].metadata.name}")
  export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].c
ontainerPort}")
  echo "Visit http://127.0.0.1:8080 to use your application"
  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT

The complicated looking commands simply get the name of the pod and the port that is being used by NGINX to create a command that will forward data from your localhost to the kubernetes cluster. That command is:

  kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT

After port-forwarding is running, you can then access http://localhost:8080/ and get this display that says NGINX is running. You'll know it's working if the port forwarding displays more logging information. Mine displayed the following:

kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
Handling connection for 8080
Handling connection for 8080

Each time you hit the URL, an additional logging line Handling connection for 8080 is displayed (and the web page displays the Welcome to NGINX page).

NGINX is running

PatS
  • 8,833
  • 12
  • 57
  • 100