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

From Wiki
Line 13: Line 13:
  kubectl run webserver --image nginx --dry-run=client -o yaml > webserver.yaml
  kubectl run webserver --image nginx --dry-run=client -o yaml > webserver.yaml


2) Edite o arquivo '''webserver.yaml''' e adicione o conteúdo:
2) Edite o arquivo '''webserver.yaml''' e adicione "replicas, ports, containerPort", como abaixo:


  <nowiki>
  apiVersion: v1
apiVersion: v1
kind: Pod
kind: Pod
metadata:
metadata:
   creationTimestamp: null
   creationTimestamp: null
   labels:
   labels:
     run: webserver
     run: webserver
   name: webserver
   name: webserver
spec:
spec:
   replicas:       3
   '''replicas: 3'''
   containers:
   containers:
   - image: nginx
   - image: nginx
Line 33: Line 32:
   dnsPolicy: ClusterFirst
   dnsPolicy: ClusterFirst
   restartPolicy: Always
   restartPolicy: Always
status: {}
status: {}


</nowiki>


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

Revision as of 19:28, 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

Arquivo de deployment webserver.yaml

1) Vamos gerar o arquivo

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

2) Edite o arquivo webserver.yaml e adicione "replicas, ports, containerPort", como abaixo:

apiVersion: v1
kind: Pod
metadata:
 creationTimestamp: null
 labels:
   run: webserver
 name: webserver
spec:
 replicas: 3
 containers:
 - image: nginx
   name: webserver
   ports:
   - containerPort: 80
   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 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