Sails (Part 3)

Neil HaddleyOctober 13, 2021

Sails and the Amazon Elastic Kubernetes Service

Dockerfile

Docker Container

Dockerfile

Dockerfile

Command Palette...

Command Palette...

Docker Image: Build Image...

Docker Image: Build Image...

haddleysails:latest

haddleysails:latest

Docker Desktop

Running the Docker image on a laptop.

The haddleysails image is displayed in Docker Desktop

The haddleysails image is displayed in Docker Desktop

Running the image

Running the image

accessing the container using http://localhost

accessing the container using http://localhost

using the container running locally to retrieve the articles data

using the container running locally to retrieve the articles data

remove the container

remove the container

no containers running

no containers running

Docker Desktop support for Kubernettes

Running Kubernettes pods on a laptop.

Using kubectl to run multiple copies of the Docker image

Using kubectl to run multiple copies of the Docker image

The Kubernettes pods running

The Kubernettes pods running

accessing the pods using http://localhost

accessing the pods using http://localhost

using the pods running locally to retrieve the articles data

using the pods running locally to retrieve the articles data

removing the application/pods

removing the application/pods

no pods/containers running

no pods/containers running

Amazon Container Services

The Docker image is pushed to the Amazon Elastic Container Registry

Create repository

Create repository

haddleysails

haddleysails

Create repository

Create repository

haddleysails repository

haddleysails repository

View push commands

View push commands

macOS / Linux commands

macOS / Linux commands

Windows commands

Windows commands

docker build -t haddleysails .

docker build -t haddleysails .

build finished

build finished

commands

commands

docker tag ...

docker tag ...

docker push ...

docker push ...

eksctl

Using eksctl to create the Amazon Elastic Kubernetes Service cluster.

eksctl create cluster --name haddley-sails

eksctl create cluster --name haddley-sails

no clusters

no clusters

creating haddley-sails

creating haddley-sails

The Amazon EKS cluster is ready

The Amazon EKS cluster is ready

The haddley-sails cluster is active

The haddley-sails cluster is active

Two nodes in the cluster

Two nodes in the cluster

Workloads

Workloads

kubectl

Using kubectl to deploy the application to the cluster

kubectl apply -f haddley-sails.yaml

kubectl apply -f haddley-sails.yaml

2 pods desired

2 pods desired

2 pods ready

2 pods ready

Pods

Pods

external ip address

external ip address

home page

home page

Articles

Articles

Dockfile

YAML
1FROM node:8
2LABEL maintainer="Azure App Service Container Images <appsvc-images@microsoft.com>"
3
4# Create app directory
5WORKDIR /app
6
7# Bundle app source
8COPY . .
9RUN npm install
10
11EXPOSE 1337
12CMD [ "npm", "start" ]

haddley-sails-local.yaml

YAML
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4  name: haddley-sails-deployment
5  labels:
6    app: haddley-sails
7spec:
8  replicas: 2
9  selector:
10    matchLabels:
11      app: haddley-sails
12  template:
13    metadata:
14      labels:
15        app: haddley-sails
16    spec:
17      containers:
18        - name: haddley-sails
19          image: haddleysails
20          imagePullPolicy: Never
21          ports:
22            - containerPort: 1337
23---
24apiVersion: v1
25kind: Service
26metadata:
27  name: haddley-sails-service
28spec:
29  selector:
30    app: haddley-sails
31  ports:
32    - protocol: TCP
33      port: 80
34      targetPort: 1337
35  type: LoadBalancer

haddley-sails.yaml

YAML
1apiVersion: apps/v1
2kind: Deployment
3metadata:
4  name: haddley-sails-deployment
5  labels:
6    app: haddley-sails
7spec:
8  replicas: 2
9  selector:
10    matchLabels:
11      app: haddley-sails
12  template:
13    metadata:
14      labels:
15        app: haddley-sails
16    spec:
17      containers:
18        - name: haddley-sails
19          image: haddleysails:latest
20          ports:
21            - containerPort: 1337
22---
23apiVersion: v1
24kind: Service
25metadata:
26  name: haddley-sails-service
27spec:
28  selector:
29    app: haddley-sails
30  ports:
31    - protocol: TCP
32      port: 80
33      targetPort: 1337
34  type: LoadBalancer