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.
Building Temperstack | AI Agent for Software Reliability | AI SRE Agent
1 年Andrew, ??
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
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.