Wednesday, January 1, 2025

Getting Kubernetes up and running easy

So, you’ve finally managed to get Minikube up and running. The Kubernetes gods have smiled upon you, and you’re now basking in the glorious complexity of your local cluster. Kubelet is purring, the API server is churning away, and you have the world at your fingertips. At least, that’s what you told yourself when you started.

But then reality set in. You went to run minikube service nginx-service, expecting a smooth, majestic reveal of your application to the outside world. Instead, you got hit with the error:

"❌ Exiting due to SVC_NOT_FOUND: Service 'nginx.service' was not found in 'default' namespace."

Oh, the sweet taste of failure. It’s almost like Kubernetes has its own way of reminding you that it doesn’t care about your dreams or intentions. It doesn’t care that you spent hours configuring your cluster. In fact, it seems to take delight in watching you struggle to “find” the service that you swore you created just minutes ago.

But don’t worry! The path to Kubernetes enlightenment is paved with errors, confusion, and head-scratching moments. Here’s how you can actually get your nginx-service up and running without throwing your laptop out the window.


Step 1: Check Your Service (because Kubernetes won’t)

First, let’s face the music. If you ran minikube service nginx-service and it didn’t work, there’s a good chance your service never existed in the first place. Kubernetes isn’t exactly the most forgiving friend—it won’t remind you of things like services or resources unless you explicitly ask for them. And even then, it might just give you a cryptic error and leave you guessing.

So, what should you do? Check the list of services that actually exist:

kubectl get services

If your service isn’t on the list, well, welcome to the club. It’s time to reapply your service YAML. Maybe it didn’t get created, or perhaps it was just one of those days where Kubernetes decided to play hard-to-get. Either way, it’s time to step up your game.


Step 2: Create the Service (Again)

At this point, you’re probably thinking, “Didn’t I do this already?” Yes, yes you did. But you must’ve missed something. Kubernetes is like that one friend who only shows up when you make a huge deal about their attendance. If the YAML wasn’t perfect or you missed a small indentation, the service never stood a chance.

Here’s a simple service YAML to get your nginx-service working. Yes, it’s basic. Yes, it’s what every tutorial tells you to use. But sometimes, basic is best, and if it works, don’t question it.

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: NodePort

Now, apply it:

kubectl apply -f nginx-service.yaml

Step 3: Double-Check That Pod (Spoiler: It Might Not Be Running)

Services don’t magically run themselves. They rely on pods, which need to be in a running state. If your pod isn’t running (say, because your Nginx container forgot how to launch itself), then no amount of service configuration will help you.

You can check the pods with:

kubectl get pods

If your pod isn’t running, guess what? You’ve got more work to do. Run an Nginx deployment to create the pod, like so:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:latest
          ports:
            - containerPort: 80

Apply it:

kubectl apply -f nginx-deployment.yaml

Step 4: Re-check the Service List

After your pod is running, the service should be ready to do its job. Run kubectl get services again to see if nginx-service is now happily listed.

If it is, you can finally breathe easy (for now). Try accessing it via Minikube:

minikube service nginx-service

Kubernetes has finally allowed you to glimpse the future, or at least, the basic web page that Nginx serves by default.


Step 5: Port-Forwarding (When All Else Fails)

If Minikube service is still being stubborn and refuses to show you the goods, you can manually port-forward the service to your local machine:

kubectl port-forward service/nginx-service 8080:80

Now, visit http://localhost:8080, and you should see your Nginx page. It’s not glamorous, but it’s your Kubernetes page.


A Few Parting Words (Or Should I Say, Warnings?)

After all of this, you may feel victorious, but don’t get cocky. Kubernetes will always find a new way to humble you. One day it’s refusing to create a simple service, and the next it’s trying to make your entire cluster vanish because you missed a semicolon. It's a complex beast, and as you become more familiar with it, you’ll realize that every mistake is just an opportunity to learn—or scream.

In the meantime, if you ever find yourself questioning your decision to dive into Kubernetes, remember: Minikube doesn’t care about your mental health. It’s here to challenge you, test your patience, and make you question whether this is really what you want to do with your time. But stick with it, because, like any worthy endeavor, the rewards are well worth the struggle.

In the end, Kubernetes isn’t just a platform. It’s a journey. A long, error-filled, confusing journey, with the occasional successful minikube service command to remind you that, yes, you are capable of this much.

Welcome to Kubernetes.

No comments:

Post a Comment

Understanding the React Renderer: What Happens Behind the Scenes

If you’ve been working with React for a while, you’ve probably encountered the term React Renderer . But what exactly is it, and why is it ...