1

There is this example project on GitHub that I'm trying to deploy on local Kubernetes cluster (k3d). The developers of Proto.Actor described the k8s deployment pretty much here in the official docs. The problem is that the documentation is deploying on Azure Kubernetes Service whereas I want to deploy on local k8s cluster (k3d).

As much as I understand the steps, it's as following:

  1. Build docker images for both projects in the solution [I was able to do that step]
docker build -f ./ProtoClusterTutorial/Dockerfile . -t proto-cluster-tutorial:1.0.0`
docker build -f ./SmartBulbSimulatorApp/Dockerfile . -t smart-bulb-simulator-app:1.0.0`
  1. Push the docker images into a repository

Push the docker images where? Local k3d repository? Docker Hub? GitHub Container Registry?

Next question, the file values.yaml in the Helm chart directory consists of a repository field (here). If I push the docker image to ghcr or Docker hub, I'll just put the image link there, but what if I have to use the k3d local repository? What link should I use in that case?

The next question is how does kubectl get pods know that it has to display the k3d cluster pods and not the Docker Desktop Kubernetes which I have enabled?

I would be grateful if you briefly list the steps that I have to accomplish using k3d, Helm chart and kubectl.

nop
  • 4,711
  • 6
  • 32
  • 93

1 Answers1

2

It doesn't matter where you push your images to, as long as it's a valid implementation of the OCI Distribution Spec (a valid container registry). All the registry options you've listed would work, just pick the one that fits your needs.

Regarding the values.yaml file, the repository field is the url to the repository, depending on which container registry you decide to use (docker.io for Docker Hub, ghcr.io for Github Container Registry, etc.) Please check the docs of the container registry you choose for specific instructions of setting up repositories, building, pushing and pulling.

kubectl gets it's configuration from a config file, which can contain multiple clusters. The k3d install script is most likely adding the new cluster as an entry to the config file and setting it as the new context for kubectl.

Back to your problem. A simpler solution might be to import the images in k3d manually as noted in this answer. I haven't used k3d myself so I can't guarantee this method will work, but it seems like a much simpler approach that can save you a lot of headache.

In case, however, you want to get your hands dirty and learn more about container repositories, helm and k8s, here's an example scenario with a repository hosted on localhost:5000 and I strongly encourage you to check the relevant docker/helm/kubernetes docs for each step

  1. Login to your registry
docker login localhost:5000
  1. Build the images
//Note how the image tag includes the repository url where they'll be pushed to
docker build -f ./ProtoClusterTutorial/Dockerfile . -t localhost:5000/proto-cluster-tutorial:1.0.0
docker build -f ./SmartBulbSimulatorApp/Dockerfile . -t localhost:5000/smart-bulb-simulator-app:1.0.0
  1. Push the images
docker push localhost:5000/proto-cluster-tutorial:1.0.0
docker push localhost:5000/smart-bulb-simulator-app:1.0.0
  1. Edit the values.yaml
  image:
    repository: localhost:5000/proto-cluster-tutorial
    pullPolicy: IfNotPresent
    tag: "1.0.0"
  1. Run helm install with the modified values.yaml file

One thing I've noticed is that guide's helm chart does not include a field for imagePullSecrets since they are using Azure Container Registry and hosting the cluster on Azure which handles the authentication automatically. This means that private repositories will not work with the chart in your scenario and you'll have to edit the helm chart and subsequently the values.yaml to make it work. You can read more about imagePullSecrets here

  • Thank you for the answer! It was really helpful! I pushed the docker image to Docker Hub and then ran `helm install...` which led to an error that there was no Kubernetes cluster running and I had to do `k3d cluster create two-node-cluster --agents 2` which created k3d cluster and fixed it. However, `Error: INSTALLATION FAILED: template: market-data-service/templates/service.yaml:6:18: executing "market-data-service/templates/service.yaml" at <.Values.member.service.type>: nil pointer evaluating interface {}.service`. Btw I renamed the project names – nop Sep 10 '22 at 21:24
  • 1
    This is most likely because your values.yaml file is missing `member.service` field and its children fields. When I said edit the `values.yam` i meant only the repository section and keep everything else the same. Is that the case? – stefanbankow Sep 11 '22 at 08:59
  • 1
    Thank you! I accidentally changed `member` in values.yaml to smt else. It works, thanks again! – nop Sep 11 '22 at 13:59