Kubernetes
This is a Kubernetes Section!
Cheat Sheet - really good one!
Manifests | YAML
Basic structure
Pod
- Simple example (Pod)
 
YAML
apiVersion: v1
kind: Pod
metadata:
  name: nginx
  labels:
    app: nginx
    tier: frontend
spec:
  containers:
  - name: nginx
    image: nginx
ReplicaSet
YAML
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: my-replicaset
  labels:
    name: my-replicaset-app
    type: frontend
spec:
  template:
    metadata:
      name: my-replicaset-pod
      labels:
        app: myapp-replicated
        type: frontend
    spec:
      containers:
      - name: nginx-controller
        image: nginx
  replicas: 3
  selector:
    matchLabels:
      type: frontend 
Deplyoment
This is a way to go
YAML
apiVersion: apps/v1
kind: Deployment
metadata:
  name: frontend-deployment
  labels:
    app: myapp
    type: frontend
spec:
  template:
    metadata:
      name: myapp-test
      labels:
        app: myapp
        type: frontend
    spec:
      containers:
      - name: nginx-controller
        image: nginx
  replicas: 3
  selector:
    matchLabels:
      app: myapp
 
Service
YAML
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    app: nginx
    svc: nginx
spec:
  type: LoadBalancer
  loadBalancerIP: 100.100.100.150
  selector:
    app: nginx # Target the deplyoment/pod label
  ports:
    - protocol: TCP
      port: 80
kubectl basics
Create an NGINX Pod
Generate POD Manifest YAML file (-o yaml). Don't create it(--dry-run)
Create a deployment
Generate Deployment YAML file (-o yaml). Don't create it(--dry-run)
Generate Deployment YAML file (-o yaml). Don’t create it(–dry-run) and save it to a file.
Deployment with 4 replicas.
Bash
kubectl create deployment --image=nginx nginx --replicas=4 --dry-run=client -o yaml > nginx-deployment.yaml
Scale replicas
Create Services | ClusterIP
This will not use the pods labels as selectors, instead it will assume selectors as app=redis
Create Services | NodePort
Bash
kubectl expose pod nginx --type=NodePort --port=80 --name=nginx-service --dry-run=client -o yaml
This will automatically use the pod's labels as selectors, but you cannot specify the node port.
This will not use the pods labels as selectors