Getting Started with Deploying Applications to Kubernetes: A Beginner’s Guide for Local Environments

Andrés Cabrera
2 min readApr 8, 2023

--

Kubernetes is a widely used container orchestration platform for deploying and managing containerized applications. In this tutorial, we’ll walk you through creating a local Kubernetes cluster with an Ingress Controller to easily route external traffic to your applications, and deploying your applications to Argocd.

To start, we need to create a configuration file specifying the desired state of the Kubernetes cluster. Here is an example YAML file:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- containerPort: 443
hostPort: 443
protocol: TCP
- role: worker
- role: worker

In this YAML file, we specify the number of nodes required for our cluster and add an InitConfiguration for the Ingress Controller. This configuration creates one control-plane node and two workers.

To apply this configuration, we can use the kind command:

kind create cluster --config config.yaml --name cluster01

With the Kubernetes cluster running, we can now deploy the Ingress Controller:

kubectl apply --filename https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml

Once this installation is complete, we can start deploying our application.

Now, we will create our deployment and service.

This installs the Ingress Controller on our cluster, allowing us to route traffic to our services.

Next, we need to create a deployment and service for our application. Here are the example YAML files:

apiVersion: apps/v1
kind: Deployment
metadata:
name: podinfo
spec:
selector:
matchLabels:
app: podinfo
template:
metadata:
labels:
app: podinfo
spec:
containers:
- name: podinfo
image: stefanprodan/podinfo
ports:
- containerPort: 9898
apiVersion: v1
kind: Service
metadata:
name: podinfo
spec:
ports:
- port: 80
targetPort: 9898
selector:
app: podinfo

Finally, we need to create an Ingress resource to route traffic to our service:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: podinfo
spec:
ingressClassName: nginx
rules:
- http:
paths:
- backend:
service:
name: podinfo
port:
number: 80
path: /
pathType: Prefix

With the deployment, service, and Ingress resource in place, we can now test our application by accessing it through the Ingress Controller.

Now, we can open localhost in our browser to see our deployed app.

localhost

To retrieve logs from the Ingress Controller when accessing our application, we can use the kubectl logs command to view the logs for the specific pod that the Ingress Controller is running on.

172.18.0.1 - - [08/Apr/2023:17:21:42 +0000] "GET / HTTP/1.1" 200 5489 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36" 667 0.002 [default-podinfo-80] [] 10.244.1.16:9898 5489 0.002 200 2fb0ff3bc50590da44cfd39680c0d831

By following this guide, you’ll learn how to deploy applications to Argocd from the very basics. With the Kubernetes cluster running and the Ingress Controller installed, you can easily route external traffic to your applications, making it perfect for local development and testing.

In the next post, we will use Argocd’s Application and ApplicationSet to deploy our applications.

--

--

Andrés Cabrera

Growth-oriented collaborator experienced in systems administration, embracing DevOps philosophy for continuous learning and finding opportunities in mistakes.