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:
- 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`
- 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.
CodePudding user response:
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
- Login to your registry
docker login localhost:5000
- 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
- Push the images
docker push localhost:5000/proto-cluster-tutorial:1.0.0
docker push localhost:5000/smart-bulb-simulator-app:1.0.0
- Edit the
values.yaml
image:
repository: localhost:5000/proto-cluster-tutorial
pullPolicy: IfNotPresent
tag: "1.0.0"
- Run
helm install
with the modifiedvalues.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