Kubernetes: Deploy de uma aplicação via Linha de comando: Difference between revisions

From Wiki
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 4: Line 4:
= Procedimento =
= Procedimento =


== Arquivo de deployment webserver.yaml ==


1) Crie o arquivo '''webserver.yaml''' e adicione o conteúdo:
 
 
== Gerando um arquivo yaml ==
 
1) Vamos gerar o arquivo
 
kubectl run webserver --image nginx --dry-run=client -o yaml > w.yaml
 
Abaixo temos o arquivo gerado '''w.yaml'''
 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: webserver
  name: webserver
spec:
  containers:
  - image: nginx
    name: webserver
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Always
status: {}
 
 
Salve e feche o arquivo.
 
2) Execute o comando kubectl para fazer o deploy das informações no arquivo
 
kubectl create -f .yaml
 
= Usando um deployment =
 
Crie


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


Salve e feche o arquivo.
Salve e feche o arquivo.

Latest revision as of 19:33, 15 June 2020

Vamos fazer o deploy de uma aplicação no Kubernetes usando linha de comando (cli). Neste exemplo vamos fazer deploy de um webserver Nginx.


Procedimento

Gerando um arquivo yaml

1) Vamos gerar o arquivo

kubectl run webserver --image nginx --dry-run=client -o yaml > w.yaml

Abaixo temos o arquivo gerado w.yaml

apiVersion: v1
kind: Pod
metadata:
 creationTimestamp: null
 labels:
   run: webserver
 name: webserver
spec:
 containers:
 - image: nginx
   name: webserver
   resources: {}
 dnsPolicy: ClusterFirst
 restartPolicy: Always
status: {}


Salve e feche o arquivo.

2) Execute o comando kubectl para fazer o deploy das informações no arquivo

kubectl create -f .yaml

Usando um deployment

Crie

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

Salve e feche o arquivo.

2) Execute o comando kubectl para fazer o deploy das informações no arquivo

kubectl create -f webserver.yaml

Verificando o que foi criado

  • Deployments
kubectl get deployments

NAME        READY   UP-TO-DATE   AVAILABLE   AGE
webserver   3/3     3            3           8m31s
  • ReplicaSets
kubectl get replicasets

NAME                   DESIRED   CURRENT   READY   AGE
webserver-7b45b4c665   3         3         3       3m53s
  • Pods
kubectl get pods

NAME                         READY   STATUS    RESTARTS   AGE
webserver-7b45b4c665-kc94b   1/1     Running   0          4m5s
webserver-7b45b4c665-pcs5g   1/1     Running   0          4m5s
webserver-7b45b4c665-t567q   1/1     Running   0          4m5s

Criando um serviço e expondo-o ao mundo externo com o NodePort via Linha de Comando

Continua em Kubernetes: Criando um serviço e expondo-o ao mundo externo com o NodePort via Linha de Comando

Ver também