How do i deploy a kubernetes app using a yaml file?



  • This example is fairly common on the internet, it deploys a nginx webserver, labels it, creates 3 replicasets, specifies the app should run on port 80. Looking at it, you can break down blocks of it. There are two spec: sections because one is for the Deployment, and one is for the container template.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: webserver
      labels:
        app: nginx
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:alpine
            ports:
            - containerPort: 80
    

    To deploy from this file do the following:

    $ kubectl create -f webserver.yaml 
    deployment "webserver" created
    
    $ kubectl get replicasets
    NAME                   DESIRED   CURRENT   READY     AGE
    webserver-77d8994b6f   3         3         3         41s
    
    $ kubectl get pods -l app==nginx
    NAME                         READY     STATUS    RESTARTS   AGE
    webserver-77d8994b6f-fn9p9   1/1       Running   0          1m
    webserver-77d8994b6f-pr28r   1/1       Running   0          1m
    webserver-77d8994b6f-qnqlq   1/1       Running   0          1m
    

Log in to reply
 

© Lightnetics 2024