configmap-def.yaml

1
2
3
4
5
6
7
8
9
apiVersion: v1
kind: ConfigMap
metadata: 
  name: app-config 
data: 
  APP_COLOR: blue
  APP_MODE: prod
  MY_NUMBER: 3.14
  FAV_PATH: "/usr/local/bin"

deployment-def.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Remember, every K8s object has apiVersion, kind, metadata, and a spec.
apiVersion: apps/v1

# 1. This config is nearly identical to ReplicaSet, except for the kind.
kind: Deployment
metadata:

  # 2. We also named it appropriately.
  name: myapp-deployment
  labels:
    app: myapp
    type: front-end
    super: mario
spec:
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
        boop: blarp
    spec:
      containers:
        - name: nginx-container
          image: nginx
  selector: 
    matchLabels:
      type: front-end
  replicas: 3

ingress-controller-def.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
   name: nginx-ingress-controller
spec:
   replicas: 1
   selector:
      matchLabels:
         name: nginx-ingress
   template:
      metadata:
         labels:
            name: nginx-ingress
      spec:
         containers:
         -  name: nginx-ingress-controller
            image: quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.21.0
         
         # 1. Command to run nginx server;
         args:
            - "/nginx-ingress-controller"
            - "--configmap-$(POD_NAMESPACE)/nginx-configuration"
         
         # 2. Set environment variables for Pod;
         env:
         -  name: POD_NAME
            valueFrom:
               fieldRef:
                  fieldPath: metadata.name
         -  name: POD_NAMESPACE
            valueFrom:
               fieldRef:
                  fieldPath: metadata.namespace
               
         # 3. Specify the ports ued by the ingress controller.
         ports:
         -  name: http
            containerPort: 80
         -  name: https
            containerPorts: 443

namespace-dev.yaml

1
2
3
4
apiVersion: v1
kind: Namespace
metadata:
  name: dev

pod-def.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#1 Version of K8s API to use.
apiVersion: v1

#2 Kind of object being created.
kind: Pod

#3 Describes K8s the object; "name" and "labels" are a few of many valid keys.
metadata:
   name: myapp-pod
   labels:
      app: myapp
      type: front-end
      nonsensical-bologna: boop 
      # You can put any key/value pairs you want in labels.
      # While "app" and "type" seem like they may be important labels, they are
      # something that we will use to organize our objects. 
      
#4 The desired state of the object which K8s will work to maintain.
spec:
   containers:
      - name: nginx-container
        image: nginx

replicaset-def.yaml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Remember, every K8s object has apiVersion, kind, metadata, and a spec.
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: myapp-replicaset
  labels:
    app: myapp
    type: front-end
    guess_what: chicken_butt
spec:

  #1 Provides a template of a pod we wish to create when needed.
  template:
    metadata:
      name: myapp-pod
      labels:
        app: myapp
        type: front-end
        boop: blarp
    spec:
      containers:
        - name: nginx-container
          image: nginx

  #2 This ReplicaSet will watch for all pods that have metadata.type: front-end
  selector: 
    matchLabels:
      type: front-end

  #3 Watch for 3 objects matching the above selector. 
  replicas: 3