Skip to content

Using Yaml File

Creating deployment Using yaml

  • Create a deployment.yaml file.

  • Add this code.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-hello
spec:
  replicas: 5
  selector:
    matchLabels:
      app: web-hello
  template:
    metadata:
      labels:
        app: web-hello
    spec:
      containers:
      - name: web-hello
        image: prabinkumarbaniya/k8s-web-hello
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
        ports:
        - containerPort: 3000
  • To apply this yaml file
kubectl apply -f deployment.yaml

Creating service using yaml

  • Create a service.yaml file

  • Add this code.

apiVersion: v1
kind: Service
metadata:
  name: web-hello
spec:
  type: LoadBalancer
  selector:
    app: web-hello
  ports:
  - port: 3030
    targetPort: 3000
  • To apply this yaml file
kubectl apply -f service.yaml

Deleting the deployment and service using yaml file

kubectl delete -f deployment.yaml -f service.yaml