Run Deployment

kubectl run apache --image=httpd --port=80 
kubectl run nginx --image=nginx --port=80
kubectl create -f pod-definition.yaml</br>
always contain 4 top level/properties (required) in the configuration file:

apiVersion:
kind:
metadata:

spec:
kubectl create -f nginx-basic.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:latest
        ports:
        - containerPort: 80
kubectl set image deployment/nginx nginx=nginx:1.16.1 --record
kubectl edit deployment nginx
kubectl rollout status deployment/nginx
kubectl describe deployment nginx
kubectl rollout history deployment nginx

https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

Exposing Deployment Using Service

KUBERNETES SERVICE TYPE:

  1. ClusterIP Service (default) : exposes the service on an internal IP in the cluster. This type makes the Service only reachable from within the cluster.
  2. NodePort Service : exposes the service on the same port of each selected Node in the cluster using NAT. Makes a service accessible from outside the cluster using NodeIP:NodePort.
  3. LoadBalancer Service : creates an external load balancer in the current cloud (if supported) and assigns a fixed, external IP to the service.
kubectl expose deployment nginx01 --port=80 --protocol=TCP --type=NodePort --external-ip=x.x.x.x
kubectl expose deployment nginx02 --port=80 --protocol=TCP --type=NodePort --external-ip=x.x.x.x
kubectl expose deployment nginx03 --type=LoadBalancer --name=nginx03 --external-ip=x.x.x.x
kubectl create -f nginx-svc-clusterip.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx
  name: nginx01
  namespace: default
spec:
  clusterIP: 10.96.56.63
  clusterIPs:
  - 10.96.56.63
  externalIPs:
  - 10.1.2.203
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: ClusterIP
status:
  loadBalancer: {}
kubectl create -f nginx-svc-loadbalancer.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx
  name: nginx03
  namespace: default
spec:
  allocateLoadBalancerNodePorts: true
  clusterIP: 10.106.55.141
  clusterIPs:
  - 10.106.55.141
  ports:
  - nodePort: 30792
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: LoadBalancer
status:
  loadBalancer: {}
kubectl create -f nodeport.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx
  name: nginx02
  namespace: default
spec:
  clusterIP: 10.104.174.240
  clusterIPs:
  - 10.104.174.240
  externalIPs:
  - 10.1.2.203
  ports:
  - nodePort: 31598
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: NodePort
status:
  loadBalancer: {}

Shell Login to Running Container

kubectl exec -it [pod-name] /bin/bash 

Set Replicas Number

kubectl scale --current-replicas=3 --replicas=1 deployment/nginx01