Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
README.md
minecraft-rc.yaml
minecraft-service.yaml

README.md

#Containers & Compute Engine: creating Minecraft Roulette with Kubernetes

This repository accompanies the Containers & Compute Engine: creating Minecraft Roulette with Kubernetes blog entry, published on 9 Nov 2015. Please follow along in the blog entry, as it provides context and explanation for this repository's contents. Files and commands may require updating as future versions of docker, gcloud, and Kubernetes are released.

All commands in this file are executed on your local or development machine.

Set up

Update and configure gcloud:

local $ gcloud components update
local $ gcloud config list
local $ gcloud config set project <project id>

Install Kubernetes and bring up a cluster:

local $ curl https://goo.gl/6y01p1 -o k8s.tar.gz
local $ tar -xvf k8s.tar.gz
local $ cd kubernetes
local $ cluster/kube-up.sh

Verify cluster information:

local $ kubectl cluster-info
local $ kubectl get nodes

Create Minecraft server pod

Define the minecraft-server.yaml file:

apiVersion: v1
kind: Pod
metadata:
  labels:
    name: minecraft-server
  name: minecraft-server
spec:
  containers:
  - name: minecraft-server
    image: gcr.io/<project id>/ftb:v3
    env:
    - name: EULA
      value: "true"
    ports:
    - containerPort: 25565
      hostPort: 25565

Tell kubectl to create it from the file:

local $ kubectl create -f minecraft-server.yaml

Verify that it is running:

local $ kubectl get pods

Describe the pod:

local $ kubectl describe pod minecraft-server

Find the IP address of the pod using gcloud:

local $ gcloud compute instances list <node name>

Create load balancer service

Define the minecraft-service.yaml file:

apiVersion: v1
kind: Service
metadata:
  labels:
    name: minecraft-lb
  name: minecraft-lb
spec:
  ports:
  - port: 25565
    targetPort: 25565
  selector:
    name: minecraft-server
  type: LoadBalancer

Tell kubectl to create it from the file:

local $ kubectl create -f minecraft-service.yaml

Get information about the services running:

local $ kubectl get services

Create replication controller

Delete the running minecraft-server pod:

local $ kubectl delete -f minecraft-server.yaml

Define the minecraft-rc.yaml file:

apiVersion: v1
kind: ReplicationController
metadata:
  name: minecraft-rc
  labels:
    name: minecraft-rc
spec:
  replicas: 3
  selector:
    name: minecraft-server
  template:
    metadata:
      labels:
        name: minecraft-server
      name: minecraft-server
    spec:
      containers:
      - name: minecraft-server
        image: gcr.io/<project id>/ftb:v3
        env:
        - name: EULA
          value: "true"
        ports:
        - containerPort: 25565
          hostPort: 25565

Tell kubectl to create it from the file:

local $ kubectl create -f minecraft-rc.yaml

Get information about the running pods:

local $ kubectl get pods

Stress testing the cluster

Try deleting a pod from the cluster:

local $ kubectl delete pod <pod name>

See that Kubernetes has restarted a pod for you:

local $ kubectl get pods

Scale up the number of pods:

local $ kubectl scale --replicas=4 replicationcontrollers minecraft-rc
local $ kubectl get pods

Scale down the number of pods:

local $ kubectl scale --replicas=2 replicationcontrollers minecraft-rc
local $ kubectl get pods