Run Deployment

kubectl run apache --image=httpd --port=80 --replicas=3 --labels="name=apache01"
kubectl run nginx --image=nginx --port=80 --replicas=3 --labels="name=nginx01"
kubectl create -f nginx-basic.yaml

#nginx-basic.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx01
  labels:
    app: nginx01
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx01
  template:
    metadata:
      labels:
        app: nginx01
    spec:
      containers:
      - name: nginx01
        image: k8s.gcr.io/nginx:1.7.9
        ports:
        - containerPort: 80

Exposing Deployment Using Service

kubectl expose deployment apache01 --port=80 --protocol=TCP --type=NodePort --external-ip=x.x.x.x
kubectl expose deployment nginx01 --type=LoadBalancer --name=nginx01 --external-ip=x.x.x.x
#kubectl create -f nginx01-svc-nodeport.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx01
  name: nginx01
  namespace: default
spec:
  clusterIP: 10.111.70.90
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 32056
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx01
  type: NodePort
status:
  loadBalancer: {}
#kubectl create -f nginx01-svc-loadbalancer.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx01
  name: nginx01
  namespace: default
spec:
  clusterIP: 10.110.90.192
  externalTrafficPolicy: Cluster
  ports:
  - nodePort: 32370
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx01
  type: LoadBalancer
status:
  loadBalancer: {}
#kubectl create -f nginx01-svc-clusterip.yaml
apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx01
  name: nginx01
  namespace: default
spec:
  clusterIP: 10.103.230.133
  ports:
  - port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx01
  type: ClusterIP
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

Updating Deployment

kubectl set image deployments/deployment-name deployment-name=registry/imageversion
kubectl rollout status deployments/deployment-name