Fading Coder

One Final Commit for the Last Sprint

Home > Tools > Content

Setting Up a Local Kubernetes Environment with Minikube on CentOS

Tools May 13 1

This guide provides a step-by-step process to install Minikube and kubectl on CentOS for creating a local single-node Kubernetes cluster.

Prerequisites and References

Official Documentation:

Install kubectl

  1. Download the Binary Obtain the kubectl binary for Linux.

  2. Grant Execution Permissions

    chmod +x ./kubectl
    
  3. Add to System Path

    sudo mv ./kubectl /usr/local/bin/kubectl
    
  4. Verify Installation

    kubectl version
    

Install Minikube

  1. Download the Minikube Binary Download the Linux AMD64 version of Minikube.

  2. Configure System Path

    sudo mv minikube-linux-amd64 minikube && chmod +x minikube && mv minikube /usr/local/bin/
    
  3. Verify Installation

    minikube version
    

Initialize a Single-Node Kubernetes Cluster

Start Minikube using the none driver, which runs Kubernetes components directly on the host rather than in a VM, and specify a mirror repository.

minikube start --vm-driver=none --image-repository=gcr.azk8s.cn/google-containers

Troubleshooting Commmon Issues

Issue: Unable to Pull Container Images

Solution: Manually pull required images from an accessible registry like Alibaba Cloud and tag them appropriately.

# Example for the kube-proxy image
# First, pull the image from the mirror.
docker pull registry.cn-hangzhou.aliyuncs.com/snail-gao/k8s:kube-proxy
# Then, retag it to match the expected name.
docker tag registry.cn-hangzhou.aliyuncs.com/snail-gao/k8s:kube-proxy gcr.azk8s.cn/google-containers/kube-proxy:v1.16.2

Issue: Network Bridge Configuration

Solution: Enable bridged traffic to be processed by iptables.

echo 1 > /proc/sys/net/bridge/bridge-nf-call-iptables
echo 1 > /proc/sys/net/bridge/bridge-nf-call-ip6tables

Exploring the Kubernetes Environment

After a successful Minikube start, you can interact with your local cluster.

Check Cluster Configuration and Status

# View current kubectl configuration
kubectl config view
# List available contexts
kubectl config get-contexts
# Display cluster endpoints
kubectl cluster-info

Working with Pods: A Practical Example

1. Create a Pod Manifest File

Create a file named nginx-pod.yaml with the following content:

apiVersion: v1
kind: Pod
metadata:
  name: web-server
  labels:
    app: webserver
spec:
  containers:
  - name: nginx-container
    image: nginx:latest
    ports:
    - containerPort: 80

2. Deploy the Pod

kubectl apply -f nginx-pod.yaml

3. Inspect the Pod

# List pods
kubectl get pods
# List pods with additional details (IP, Node)
kubectl get pods -o wide
# Get detailed description of a specific pod
kubectl describe pod web-server

4. Access the Pod's Container

# Access via kubectl exec
kubectl exec -it web-server -- /bin/bash
# Alternatively, access via Docker (if using the 'none' driver)
minikube ssh
docker ps
docker exec -it <CONTAINER_ID> /bin/bash

5. Forward Local Port to Pod

To access the NGINX server running in the pod from your local machine:

kubectl port-forward web-server 8080:80

You can now access the pod at http://localhost:8080.

6. Delete the Pod

kubectl delete -f nginx-pod.yaml

Minikube Management Commands

# Start the local Kubernetes cluster
minikube start
# Completely remove the Minikube VM and all data
minikube delete
# SSH into the Minikube node (VM or host)
minikube ssh
# Check the status of the Minikube cluster
minikube status
# Open the Kubernetes dashboard in your default browser
minikube dashboard

Minikube essentially provisions a lightweight environment (a VM or directly on the host) that contains a fully functional, single-node Kubernetes cluster, allowing you to interact with it via kubectl.

Related Articles

Efficient Usage of HTTP Client in IntelliJ IDEA

IntelliJ IDEA incorporates a versatile HTTP client tool, enabling developres to interact with RESTful services and APIs effectively with in the editor. This functionality streamlines workflows, replac...

Installing CocoaPods on macOS Catalina (10.15) Using a User-Managed Ruby

System Ruby on macOS 10.15 frequently fails to build native gems required by CocoaPods (for example, ffi), leading to errors like: ERROR: Failed to build gem native extension checking for ffi.h... no...

Resolve PhpStorm "Interpreter is not specified or invalid" on WAMP (Windows)

Symptom PhpStorm displays: "Interpreter is not specified or invalid. Press ‘Fix’ to edit your project configuration." This occurs when the IDE cannot locate a valid PHP CLI executable or when the debu...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.