Deploy an application on k3s cluster
We will deploy the mealie application on our kuberentes cluster and expose it for external access.
Step 1. Create a dedicated namespace for Mealie
k create ns mealie
## view namespaces
k get ns
Step 2. Create a deployment
Method 1: Create a YAML template using nginx image and modify the file with our application image and other app requirements.
Generate a deployment YAML file:
k create deploy mealie --image=nginx --dry-run=client -o yaml -n mealie > deploy.yaml
Edit the deploy.yaml file to customize it for Mealie.
Make the following changes:
- Replace the image with the Mealie image:
image: ghcr.io/mealie-recipes/mealie:v3.11.0
- Add a
portssection to expose the container port:
ports:
- containerPort: 9000
Save and exit the file.
Apply the updated deployment:
k apply -f deploy.yaml
Method 2: You could just run this single command to create the deployment:
k create deploy mealie --image=ghcr.io/mealie-recipes/mealie:v3.11.0 --port=9000 -o yaml -n mealie
If you want a manifest (YAML file), dry run the above command and then apply that file like this:
k create deploy mealie --image=ghcr.io/mealie-recipes/mealie:v3.11.0 --port=9000 --dry-run=client -o yaml -n mealie > deploy.yaml
k apply -f deploy.yaml
Verify that the pods are running:
k get pods -o wide -n mealie
Step 3. Access the application internally
curl <pod_ip>:9000
We can get the pod's IP from the previous command.
Step 4. Expose application for external access
Now, we can expose the application using a service:
k expose deployment mealie --type=LoadBalancer --port=8080 --target-port=9000 -n mealie
k3s automatically assigns an external IP for service of type LoadBalancer.
Step 5. Access application externally
Get the external IP of the service from:
k get svc -n mealie
We can now reach our application from an external browser using the external ip and port number:
http://<external_ip>:8080
We are able to curl directly to the External IP.
Now try to access it from another desktop:
There we go! We have successfully deployed the mealie application and made it available to reach from anywhere!