Getting Started with Minikube: Setting Up a Local Kubernetes Cluster

Getting Started with Minikube: Setting Up a Local Kubernetes Cluster

If you're new to Kubernetes and want to experiment with it on your M1 MacBook, Minikube is the perfect tool to set up a local development cluster quickly. In this article, I'll walk you through the installation and configuration of Minikube and guide you in deploying a simple nginx web application to your local Kubernetes cluster.

The yamls created for this guide can be found here.


Step 1: Installing Minikube

Before we begin, ensure you have Homebrew installed on your MacBook. Open Terminal and run the following commands:

brew update
brew install minikube        

This will install Minikube on your machine, making it ready for use.


Step 2: Starting the Minikube Cluster

With Minikube installed, launch a new Kubernetes cluster by running the following command:

minikube start --driver=docker -p <profile-cluster-name>        

Minikube supports different drivers like hyperkit, and we're using `docker` as it works on an M1 Macbook. The process may take a few minutes to complete.


Step 3: Verifying the Cluster

Confirm that the Minikube cluster is up and running by executing the following:

minikube status        

You should see a response indicating that the cluster is running and the Kubernetes API server is accessible


Step 4: Creating a Kubernetes Deployment

To deploy the nginx application, we need to create a Kubernetes Deployment manifest named app-deployment.yaml with the following content. Note that if you do try and pull from a private repository, you will need to setup a Kubernetes secret using the docker credentials and add it to the deployment yaml.

apiVersion: apps/v1
kind: Deployment
metadata:
? name: minkube-app
spec:
? replicas: 2
? selector:
? ? matchLabels:
? ? ? app: minikube-app
? template:
? ? metadata:
? ? ? labels:
? ? ? ? app: minikube-app
? ? spec:
? ? ? containers:
? ? ? - name: minkube-app
? ? ? ? image: nginx:latest        

This Deployment will run two replicas of our nginx application using the latest Nginx Docker image. You can specify the type of cluster; NodePort, LoadBalancer, ExternalName. We are using the default which is ClusterIP.

Step 5: Deploying the Application

Now, use kubectl to apply the Deployment to your Minikube cluster:

kubectl apply -f app-deployment.yaml        

Minikube will create two replicas of your nginx application and manage its lifecycle.

Step 6: Accessing the Application

To access your deployed nginx application, expose it via a Kubernetes Service. Create a Service manifest named app-service.yaml:

apiVersion: v1
kind: Service
metadata:
? name: minikube-app
spec:
? selector:
? ? app: minikube-app
? ports:
? ? - protocol: TCP
? ? ? port: 80
? ? ? targetPort: 80        

Now, apply the Service configuration:

kubectl apply -f app-service.yaml        

Kubernetes will assign a ClusterIP to the Service, allowing you to access the nginx service.

kubectl port-forward service/minikube-app 9001:80        

Now, you can access the Nginx application by visiting https://localhost:9001 in your web browser.

You can also run the following minikube command to expose the service.

minikube service minikube-app --url        

Cleanup

minikube stop
minikube delete -p <profile-cluster-name>
brew uninstall minikube        

Conclusion

Congratulations! You've successfully set up Minikube and deployed an nginx web application on your local Kubernetes cluster.

Mohan Narayanaswamy Natarajan

Building Temperstack | AI Agent for Software Reliability | AI SRE Agent

1 年

Andrew, ??

回复
Kishalay Bhattacharya

Cloud DevOps Engineer | Cloud Migration | 2x GCP Certified | IaC | PaaS | Kubernetes | Service Mesh Istio | Helm | GCP DevOps

1 年

Hi Andrew, thanks for putting this together, is there any similar guide to set up Jenkins with minikube, wanna deploy the pods via pipeline

回复
Matthew T.

Cloud Systems Engineer @ Arizona State University

1 年

Minikube is a valuable asset for anyone wanting to test Container Orchestration before pushing to the Cloud. Minikube is also a great playground to put in the time required to become proficient with Kubernetes.

回复

要查看或添加评论,请登录

Andrew Mealy的更多文章

  • Getting Started with Minikube: Configuring Add-ons

    Getting Started with Minikube: Configuring Add-ons

    Minikube enables users to experiment with Kubernetes features and workflows without the complexity of a full-scale…

    1 条评论
  • Zero-Downtime Deployments in AWS

    Zero-Downtime Deployments in AWS

    A brief overview and concepts using Rolling and Blue-Green Deployments. AWS CodeDeploy There are many ways to achieve…

    1 条评论
  • Transition From Dev To DevOps

    Transition From Dev To DevOps

    A personal reflection on why and how I made the move from a developer to DevOps. The History Through my entire…

    2 条评论

社区洞察

其他会员也浏览了