James Sherry PRO
Web Development Tutor and Co-Founder of { The Jump } Digital School
Docker & Kubernetes:
A Practical guide
The wiki page details things well, but in short:
Parts of Docker
Tools
Both redundant in the presence of Kubernetes.
A Docker image is a read-only template used to build containers. Images are used to store and ship applications.
Analogy: Images are like flatpack furniture
docker pull node:9.1
docker images
Important notes:
Answer on next page
(or if you checkout the 'dockerised' branch)
FROM openjdk:7 # Base image
COPY . /usr/src/app # copy current dir into /usr/src/app INSIDE the container's file system
WORKDIR /usr/src/app # CD to that Directory
RUN apt-get update \
&& apt-get install -y --no-install-recommends maven # get maven
RUN mvn clean package # build the jar
CMD ["java", "-jar", "./target/test-artifact-0.0.1-SNAPSHOT.jar"] # run
(Click on openjdk:7 to see what happens in a base image)
Here, our CMD overrides the CMD in openjdk:7
Create deployment
kubectl run myApp --image=myApp:0.0.1
Expose Service
kubectl expose deployment myApp —type=NodePort
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: openam
spec:
replicas: 1
selector:
matchLabels:
run: openam
template:
metadata:
labels:
run: openam
spec:
containers:
- image: 10.112.159.88:40007/local-access-mgmt-service
imagePullPolicy: IfNotPresent
name: openam
env:
- name: TEST_VAR
value: "Successfully Overridden"
ports:
- containerPort: 9080
name: app-port
- containerPort: 50388
name: dir-port
- containerPort: 4443
name: dir-admin-port
- containerPort: 1688
name: dir-jmx-port
liveness
restartPolicy: Always
hostAliases:
- ip: "127.0.0.1"
hostnames:
- "online.test-lloydsbank.local"
- "ihs2.test-lloydsbank.local"
- "ihs3.test-lloydsbank.local"
apiVersion: v1
kind: Service
metadata:
name: openam
labels:
run: openam
spec:
type: NodePort
ports:
- port: 39080
nodePort: 30001
targetPort: app-port
protocol: TCP
name: app-port
- port: 50388
nodePort: 30002
targetPort: dir-port
protocol: TCP
name: dir-port
- port: 34443
nodePort: 30003
targetPort: dir-admin-port
protocol: TCP
name: dir-admin-port
- port: 31688
nodePort: 30004
targetPort: dir-jmx-port
protocol: TCP
name: dir-jmx-port
selector:
run: openam
Structure your YAML files according to https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.9/#-strong-api-overview-strong-
By James Sherry
Docker & Kubernetes