More information for the workshop can be found here.
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.
The code referenced can be found in the directory
src
- 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
- 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
- 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
- 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>
-
Using your browser:
$ kubectl delete pod apple-app banana-app
pod "apple-app" deleted
pod "banana-app" deleted
- 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
- 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
When you're ready, try out these exercises here