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

From Wiki
 
(9 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:


  apiVersion: apps/v1
 
  kind: Deployment
== 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:
  metadata:
  name: webserver
  creationTimestamp: null
  labels:
  labels:
    app: nginx
    run: webserver
  name: webserver
  spec:
  spec:
  replicas: 3
  containers:
  selector:
  - image: nginx
    matchLabels:
    name: webserver
      app: nginx
    resources: {}
  template:
  dnsPolicy: ClusterFirst
    metadata:
  restartPolicy: Always
      labels:
status: {}
        app: nginx
 
    spec:
 
      containers:
Salve e feche o arquivo.
        - name: nginx
 
          image: nginx:alpine
2) Execute o comando kubectl para fazer o deploy das informações no arquivo
          ports:
 
            - containerPort: 80
kubectl create -f .yaml
 
= Usando um deployment =
 
Crie
 
<nowiki>
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
</nowiki>


Salve e feche o arquivo.
Salve e feche o arquivo.
Line 36: Line 72:
  kubectl create -f webserver.yaml
  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 =
= Ver também =

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