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:
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