Kubernetes: Deploy de uma aplicação via Linha de comando: Difference between revisions
(One intermediate revision by the same user not shown) | |||
Line 7: | Line 7: | ||
== | == Gerando um arquivo yaml == | ||
1) Vamos gerar o arquivo | 1) Vamos gerar o arquivo | ||
kubectl run webserver --image nginx --dry-run=client -o yaml > | kubectl run webserver --image nginx --dry-run=client -o yaml > w.yaml | ||
Abaixo temos o arquivo gerado ''' | Abaixo temos o arquivo gerado '''w.yaml''' | ||
apiVersion: v1 | apiVersion: v1 | ||
Line 31: | Line 31: | ||
status: {} | 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> | |||
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. |
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