Skip to content

Lecture #03 - 09/22/2018

Agenda

  • Sidecar Pattern
  • Ambassadors
  • Adapters
  • Kubernetes Lab
  • Assignment #01 discussion

Slides

Info

To view slides, students must login to Office 365 with their Microsoft Student Advantage account. Office 365 (Microsoft Student Advantage) access details can be found here.

Reading

Sidecar Pattern

Ambassador pattern

Adapters

Minikube

Lab

Setup

  1. Launch CentOS EC2 instance for lab. AMI id for us-east-1 is ami-9887c6e7.
  2. Update your VM with command yum update -y.
  3. Disable SE Linux on CentOS VM
  4. Install VirtualBox.
  5. yum install https://centos7.iuscommunity.org/ius-release.rpm -y && yum install dkms -y && yum install kernel-devel -y
  6. Disable secure path for CentOS.
  7. Set your ip tables in CentOS echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables.
  8. sudo reboot your VM
  9. Install Docker for CentOS.
  10. Install Minikube
  11. Install kubectl
  12. Enabling shell autocompletion for kubectl

Sample App

Save following to app.js.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
const http = require('http');
const os = require('os');

console.log("Server starting...");

var handler = function(request, response) {
  console.log("Received request from " + request.connection.remoteAddress);
  response.writeHead(200);
  response.end("You've hit " + os.hostname() + "\n");
};

var www = http.createServer(handler);
www.listen(8080);

Docker File

Create Dockerfile with following content

1
2
3
FROM node:7
ADD app.js /app.js
ENTRYPOINT ["node", "app.js"]

Creating & Running App in Docker container

Build container

1
docker build .

Listing locally stored container images

1
docker images

Running the container image

1
docker run -d -p 8080:8080 <ID>

Stopping and removing a container

1
2
docker stop <ID>
docker rm <ID>

Running a local single-node Kubernetes cluster with Minikube

Starting a Minikube virtual machine

1
minikube start --vm-driver=none

Displaying cluster information

1
kubectl cluster-info

Create App Deployment

1
kubectl run hello-minikube --image=<> --port=8080

Accessing your web application

With your pod running, how do you access it? Each pod gets its own IP address, but this address is internal to the cluster and isn’t accessible from outside of it. To make the pod accessible from the outside, you’ll expose it through a Service object.

1
kubectl expose deployment hello-minikube --type=NodePort

Examining Kubernetes Pod

1
2
kubectl get pods -o wide
kubectl describe pod <NAME>

Kubernetes Dashboard

To access the Kubernetes Dashboard, run this command in a shell after starting Minikube to get the address:

1
minikube dashboard --url

Cleanup

1
2
3
4
kubectl delete service hello-minikube
kubectl delete deployment hello-minikube
minikube stop
minikube delete