Deploying Your First Application
Basic nginx Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80kubectl apply -f deployment.yaml
kubectl get pods -l app=nginxExposing with Load Balancer
apiVersion: v1
kind: Service
metadata:
name: nginx-lb
spec:
type: LoadBalancer
selector:
app: nginx
ports:
- port: 80
targetPort: 80kubectl apply -f service.yaml
kubectl get svc nginx-lb
# Note: External IP will show once AWS LB is provisionedExposing with Ingress
Requires AWS Load Balancer Controller installed.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/scheme: internet-facing
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nginx
port:
number: 80Verify Deployment
kubectl get all
kubectl describe deployment nginx
kubectl logs -l app=nginx
kubectl exec -it <pod-name> -- nginx -vCleanup
kubectl delete -f deployment.yaml
kubectl delete -f service.yaml