Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Kubernetes

Phillip Kruger edited this page Nov 22, 2017 · 18 revisions

(Thanks to Dean James-Everett for this)

Introduction

Getting this example running on a Docker container inside Kubernetes, or more specifically, Minikube

Prerequisites

Install the following on your PC.

  • Minikube
  • Kubectl

Example on Arch Linux using the AUR and packer:

packer -S minikube kubectl-bin

this will install minikube AUR and Kubectl AUR

Minikube

You can check that minikube is install:

minikube version

Example output:

minikube version: v0.21.0

Create a minikube on your local PC:

minikube start --disk-size 50g --memory 4096 --cpus 4

You can then stop/start your minikube instance

minikube stop

minikube start

You can see if your local (mini) kubernetes is running:

kubectl get nodes

NAME STATUS AGE VERSION

minikube Ready 11h v1.7.0

Reusing the Docker daemon

As explained here you can reuse the docker environment of kubernetes:

eval $(minikube docker-env)

Maven plugin

Use this (https://github.com/deanjameseverett/maven-plugin-k8) maven plugin to deploy to kubernetes with your maven build:

   <profile>
        <id>k8</id>
        <activation>
            <property>
                <name>k8</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>com.github.deanjameseverett</groupId>
                    <artifactId>k8-maven-plugin</artifactId>
                    <version>1.0.2-SNAPSHOT</version>
                    <executions>
                        <execution>
                            <id>kubernetes</id>
                            <phase>install</phase>
                            <goals>
                                <goal>startMinikube</goal>
                                <goal>deleteImage</goal>
                                <goal>buildImage</goal>
                                <goal>undeploy</goal>
                                <goal>deploy</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>

            </plugins>

        </build>
    </profile>

Doing a mvn clean install -Dk8 will deploy the docker image to kubernetes.

The following files is used to create the docker image and kubernetes environment:

Running

The example is now running in Kubernetes. To test it on localhost, you can do a port forward:

  1. Get the ports:
kubectl get pods
NAME                                       READY     STATUS    RESTARTS   AGE
notes-example-deployment-811175253-nl3bd   1/1       Running   0          3h
notes-example-deployment-811175253-w8rzq   1/1       Running   0          3h
  1. Port forward:
kubectl port-forward notes-example-deployment-811175253-nl3bd 8080:8080

All url's the available locally on 8080

Other Kubectl commands

  • kubectl get deployments
  • kubectl get services
  • minikube ssh - into vm k8
  • minikube addons enable heapster
  • minikube dashboard
  • kubectl delete service notes-example-service
  • kubectl delete deployment notes-example-deployment
Clone this wiki locally