Skip to content

You’ve heard about it, read the book and listened to the talk, but have you actually used Kubernetes?

Notifications You must be signed in to change notification settings

CloudNativeWales/ShowMeTheKubernetes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Show Me The Kubernetes

Join the chat at

Description

More information for the workshop can be found here.

Introduction

Setup

We're going to offer 2 different ways to run a cluster:

You're more than welcome to use another service if you already know how to.

Steps

The code referenced can be found in the directory src

Create a Pod and a Service

  • Save the following to apple.yaml:
---
kind: Pod
apiVersion: v1
metadata:
  name: apple-app
  labels:
    app: apple
spec:
  containers:
    - name: apple-app
      image: denhamparry/apple:1.0.0
---
kind: Service
apiVersion: v1
metadata:
  name: apple-service
spec:
  selector:
    app: apple
  ports:
    - port: 3000
  • Send the file to Kubernetes:
$ kubectl apply -f apple.yaml
pod "apple-app" created
service "apple-service" created

Create another Pod and Service

  • Save the following to banana.yaml:
---
kind: Pod
apiVersion: v1
metadata:
  name: banana-app
  labels:
    app: banana
spec:
  containers:
    - name: banana-app
      image: denhamparry/banana:1.0.0
---
kind: Service
apiVersion: v1
metadata:
  name: banana-service
spec:
  selector:
    app: banana
  ports:
    - port: 3000
  • Send the file to Kubernetes:
$ kubectl apply -f banana.yaml
pod "banana-app" created
service "banana-service" created

Create an Ingress

  • Save the following to ingress.yaml:
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: app
  annotations:
    kubernetes.io/ingress.class: nginx
    ingress.kubernetes.io/rewrite-target: '/'
spec:
  rules:
  - host: demo.local
    http:
      paths:
      - path: /apple
        backend:
          serviceName: apple-service
          servicePort: 3000
      - path: /banana
        backend:
          serviceName: banana-service
          servicePort: 3000
      - path: /
        backend:
          serviceName: apple-service
          servicePort: 3000
  • Send the file to Kubernetes:
$ kubectl apply -f ingress.yaml
ingress.extensions "app" created

Test your cluster

  • Using curl:
$ curl demo.local
<html style="background-color:#8db600 ">
  <head>
    <title>v1.0.0</title>
  </head>
  <body style="display:flex;align-items:center;justify-content:center;color:#FFFFFF;font-family:sans-serif;font-size:6rem;margin:0;letter-spacing:-0.1em">
    <h1>Apple</h1>
  </body>
</html>
$ curl demo.local/apple
<html style="background-color:#8db600 ">
  <head>
    <title>v1.0.0</title>
  </head>
  <body style="display:flex;align-items:center;justify-content:center;color:#FFFFFF;font-family:sans-serif;font-size:6rem;margin:0;letter-spacing:-0.1em">
    <h1>Apple</h1>
  </body>
</html>
$ curl demo.local/banana
<html style="background-color:#ffe135 ">
  <head>
    <title>v1.0.0</title>
  </head>
  <body style="display:flex;align-items:center;justify-content:center;color:#000000;font-family:sans-serif;font-size:6rem;margin:0;letter-spacing:-0.1em">
    <h1>Banana</h1>
  </body>
</html>

Delete your pods

$ kubectl delete pod apple-app banana-app
pod "apple-app" deleted
pod "banana-app" deleted

Create your deployments

  • Save the following to apple-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: apple-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apple
  template:
    metadata:
      labels:
        app: apple
    spec:
      containers:
      - name: apple
        image: denhamparry/apple:1.0.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
  • Send the file to Kubernetes:
$ kubectl apply -f apple-deployment.yaml
deployment.apps "apple-deployment" configured
  • Save the following to banana-deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: banana-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: banana
  template:
    metadata:
      labels:
        app: banana
    spec:
      containers:
      - name: banana
        image: denhamparry/banana:1.0.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3000
  • Send the file to Kubernetes:
$ kubectl apply -f banana-deployment.yaml
deployment.apps "banana-deployment" configured

How do we scale deployments

  • Change the number of replicas in your deployment files:
...
  replicas: 5
...
$ kubectl apply -f apple-deployment.yaml -f banana-deployment.yaml
deployment.apps "apple-deployment" configured
deployment.apps "banana-deployment" configured

Exercises

When you're ready, try out these exercises here

Clean up

About

You’ve heard about it, read the book and listened to the talk, but have you actually used Kubernetes?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published