Combines operating system, application
Docker images de facto standard
Use, modify public images
Build your own!
Hosts container images
Can be shared, or private self-hosted
Largest, shared container registry
Always security review public images!
Be aware of supply-chain attacks
TEN7 own, Drupal and k8s friendly containers
Running instance of an application
Pod can be one or more containers
Each container shares the same localhost
IP address, DNS name, Volumes, etc.
Ensure tight coupling where needed
Apache+Varnish, NGINX+PHP-FPM
Static pods rarely created directly
Created indirectly through a managing object
Describes ideal state of a pod
Can run multiple replicas of the pod
kubectl create
objectType
kubectl apply -f /path/to/file.yml
Same format as when edited
Easily added to version control (git)
Indent-based markup format
All k8s objects can be created in YAML
apiVersion: apps/v1
kind: Deployment
Name
Labels
Annotations
metadata:
labels:
app: web
name: web
Main body of the document
Defines the object, or template of objects to create
Like a YAML document itself
Has it's own metadata, spec
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: web
name: web
spec: # Deployment's spec start here.
replicas: 1
selector:
matchLabels:
app: web
template: # Pod template starts here.
metadata:
labels:
app: web
spec:
containers:
- image: ten7/flight-deck-drupal:latest
name: web
ports:
- containerPort: 80
(Scroll down.)
Deploys definitions to cluster
$ kubectl --kubeconfig=/path/to/kubeconfig.yml apply -f /path/to/file.yml
Done by kubectl
before creation
Transaction-like, doesn't create partial objects
kubectl apply -f /path/to/file.yml
Existing object will be patched
$ kubectl --kubeconfig="/path/to/kubeconfig.yml" get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
web 1/1 1 1 8m52s
kubectl describe deployment
name
Includes operational information
Edits definition in-place on cluster
Useful for critical fixes, troubleshooting
kubectl --kubeconfig="/path/to/kubeconfig.yml" edit deployment web
kubectl get pods
$ kubectl --kubeconfig="/path/to/kubeconfig.yml" get pods
NAME READY STATUS RESTARTS AGE
web-56c74df886-46wcf 1/1 Running 0 37m
web-56c74df886-gpf9c 1/1 Running 0 3m13s
web-56c74df886-kz95s 1/1 Running 0 3m13s
deploymentName-uniqueID
Names are non-deterministic!
kubectl exec -it
command
Runs command in pod, like /bin/bash
kubectl --kubeconfig="/path/to/kubeconfig.yml" exec -it web-56c74df886-gpf9c /bin/bash
(Scroll right.)
Consistent application endpoint
Creates internal DNS name
apiVersion: v1 # The version is different!
kind: Service
metadata:
name: web
spec:
ports: # Service can have one or more ports
- name: http
port: 80
protocol: TCP
selector: # This looks familiar...
app: web
Associates Deployments to Pods...
...and Pods to Services
apiVersion: apps/v1 # Deployment def starts here.
kind: Deployment
metadata:
labels:
app: web
name: web
spec:
replicas: 1
selector: # Manages pods with label
app: web # app=web
template:
metadata:
labels: # Create pods with label
app: web # app=web
spec:
containers:
- image: ten7/flight-deck-drupal:latest
name: web
ports:
- containerPort: 80
---
apiVersion: v1 # Service def starts here.
kind: Service
metadata:
name: web
spec:
ports:
- name: http
port: 80
protocol: TCP
selector: # Route to pods with label
app: web # app=web
Allows multiple roots in same file
Separated by ---
Optional, useful for highly-related definitions
kubectl get services
kubectl describe service
name
kubectl edit services
name
ClusterIP
: default, internal only
NodePort
: Exposes port on each node
LoadBalancer
: External access
---
apiVersion: v1
kind: Service
metadata:
name: web
spec:
ports:
- name: http
port: 80
protocol: TCP
selector:
app: web
type: LoadBalancer # Create external load balancer