Posts Install kubernetes cluster using Minikube
Post
Cancel

Install kubernetes cluster using Minikube

Minikube is a tool that enables developers to run a local Kubernetes cluster for testing and development. It’s lightweight and supports various environments.

Key Features
  1. Local Kubernetes Cluster:
    • Runs a single-node Kubernetes cluster on your local machine.
  2. Multi-Driver Support:
    • Works with Docker, VirtualBox, KVM, Hyper-V, and others.
  3. Customizable Resources:
    • Configure CPU, memory, and disk allocation as needed.
  4. Addons:
    • Supports additional Kubernetes features such as metrics-server, ingress, and dashboard.
  5. Cross-Platform:
    • Compatible with Linux, macOS, and Windows.

Installation

For Linux
1
2
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
For MacOS
1
brew install minikube
Set driver
1
minikube config set driver <docker|kvm2|virtualbox>
View config
1
minikube config view
Start or Create Minikube cluster
1
minikube start
Start with different network
1
2
3
docker network create --subnet=192.168.100.0/24 minikube-net

minikube start --driver=docker --network=minikube-net
Stop Minikube cluster
1
minikube stop
Destroy Minikube cluster
1
minikube delete
Check status of Minikube cluster
1
minikube status
Launch Minikube cluster dashboard
1
minikube dashboard --port=8085 --url
See Minikube IP
1
minikube ip
Access Minikube bash
1
minikube ssh
Enable specific Minikube add-on
1
minikube addons enable <addon>
Access service exposed by Minikube
1
minikube service <service-name>

Install Kubernetes dashboard ingress using DNS

We will use a wildcard test dns *.k8s.pvt.one which is pointed to 192.168.49.2. So, it will be easy to resolve without modifying of hosts file.

1
kubectl -n kubernetes-dashboard edit svc kubernetes-dashboard

Change the type field from ClusterIP to NodePort:

1
type: NodePort

Save and exit the editor.

Get the NodePort: Run the following command to find the NodePort:

1
kubectl -n kubernetes-dashboard get svc kubernetes-dashboard

Enable ingress-

1
minikube addons enable ingress

Create an Ingress YAML File: Save the following content to dashboard-ingress.yaml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: dashboard-ingress
  namespace: kubernetes-dashboard
spec:
  rules:
  - host: dashboard.k8s.pvt.one
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: kubernetes-dashboard
            port:
              number: 80

Apply dashboard ingress-

1
kubectl apply -f dashboard-ingress.yaml

See ingress details for dns and ip attachments

1
kubectl get ingress -n kubernetes-dashboard

Now visit this dashboard url:

1
http://dashboard.k8s.pvt.one

Access remote Minikube cluster from local kubectl command

  • Check server ip and port using following command

    1
    
      minikube profile list
    
  • Copy ca.crt, client.crt, client.key from following location of server.
    • ~/.minikube/ca.crt
    • ~/.minikube/profiles/minikube/client.crt
    • ~/.minikube/profiles/minikube/client.key
  • Put these files into your local machine in ~/.kube/ directory.
  • Create config file in ~/.kube directory

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
      apiVersion: v1
      clusters:
      - cluster:
          certificate-authority: /home/<user>/.kube/ca.crt
          server: https://192.168.49.2:8443
        name: minikube
      contexts:
      - context:
          cluster: minikube
          namespace: default
          user: minikube
        name: minikube
      current-context: minikube
      kind: Config
      preferences: {}
      users:
      - name: minikube
        user:
          client-certificate: /home/<user>/.kube/client.crt
          client-key: /home/<user>/.kube/client.key
    
  • Now use this command to verify
    1
    
      kubectl cluster-info