Wednesday, February 19, 2020

Deploy a container to Kubernetes and create s service for it.Both with deployment.yml and run command

Image from: https://linuxdiaryblog.blogspot.com/2020/02/dockerfile-image-using-multiple-base.html

kubectl run letskube-deployment --image=letskube:local --port=80 --replicas=3
kubectl get deployments
kubecetl get rs
kubectl get pods

kubectl expose deployment letskube-deployment --type=NodePort

http://localhost:30263  -- on multiple browsers it shows as different hostnames as the benifit of loadbalancing

kubectl delete deployment letskube-deployment
kubectl delete service letskube-deployment

letskubedeploy.yml
-----------------



apiVersion: apps/v1
kind: Deployment
metadata:
  name: letskube-deployment
  labels:
    app: letskube
spec:
  replicas: 1
  template:
    metadata:
      name: letskube
      labels:
        app: letskube
    spec:
      containers:
      - name: letskube
        image: letskube:local
        imagePullPolicy: IfNotPresent
      restartPolicy: Always
  selector:
    matchLabels:
      app: letskube


---

apiVersion: v1
kind: Service
metadata:
  name: letskube-service
spec:
  selector:
    app: letskube
  ports:
    - port: 80
  type: NodePort
  
  


kubectl create -f .\letskubedeploy.yml

kubectl get svc

testing:
http://localhost:<port_from_above_output>

kubectl delete -f .\letskubedeploy.yml 

No comments:

Post a Comment