# Now create your manifest file running below command
vi deployment.yaml
# add following lines below into the file
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
spec:
replicas: 2
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
resources: {}
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx
spec:
type: NodePort
ports:
- targetPort: 80
port: 80
nodePort: 30008
selector:
app: nginx
# after lines been added run following command
kubectl create -f deployment.yaml
# check if the pods are running and to see what node the nginx app is running
root@master1:~# kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nginx-cd55c47f5-2g77w 1/1 Running 0 22h 10.244.1.18 worker1 <none> <none>
nginx-cd55c47f5-k5n25 1/1 Running 0 22h 10.244.1.17 worker1 <none> <none>
# list your services
root@master1:~# kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 8d
nginx NodePort 10.104.192.0 <none> 80:30008/TCP 22h