Skip to content

Instantly share code, notes, and snippets.

@Andreluizfc
Last active January 19, 2022 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Andreluizfc/f4eec0552529a8aeba1314040bb5e386 to your computer and use it in GitHub Desktop.
Save Andreluizfc/f4eec0552529a8aeba1314040bb5e386 to your computer and use it in GitHub Desktop.
GKE Basic commands

GCloud GKE Basics

É possível listar o nome da conta ativa com este comando:

gcloud auth list

É possível listar o ID de projeto com este comando:

gcloud config list project

Defina a zona padrão no Cloud Shell:

gcloud config set compute/zone us-central1-a

Defina a região padrão:

gcloud config set compute/region us-central1

Compute

Listar as instancias:

gcloud compute instances list

GKE

Criar

gcloud container clusters create [CLUSTER-NAME]

Autenticar

gcloud container clusters get-credentials [CLUSTER-NAME]

Deploy

kubectl create deployment hello-server --image=gcr.io/google-samples/hello-app:1.0 No Kubernetes, todos os contêineres são executados em um pod. kubectl get pods

Expose

Para criar um serviço Kubernetes, que é um recurso Kubernetes que permite expor seu aplicativo ao tráfego externo, execute o seguinte comando kubectl expose: kubectl expose deployment hello-server --type=LoadBalancer --port 8080 Para inspecionar o serviço hello-server, execute kubectl get: kubectl get service

Pods

image

Criar kubectl create -f pod.yaml Descrever kubectl describe pods POD-NAME Use o comando kubectl exec para executar um shell interativo dentro do pod. Isso pode ser útil para solucionar problemas de dentro de um contêiner: kubectl exec monolith --stdin --tty -c pod-name /bin/sh Use o comando kubectl label para adicionar ao pod um rótulo.

kubectl label pods POD-NAME 'secure=enabled'
kubectl get pods POD-NAME --show-labels

Services

image

kind: Service
apiVersion: v1
metadata:
  name: "monolith"
spec:
  selector:
    app: "monolith"
    secure: "enabled"
  ports:
    - protocol: "TCP"
      port: 443
      targetPort: 443
      nodePort: 31000
  type: NodePort

Use o comando gcloud compute firewall-rules para permitir tráfego para o serviço do monolith no nodeport exposto:

gcloud compute firewall-rules create allow-monolith-nodeport \
  --allow=tcp:31000

Deployment

As implantações são uma maneira declarativa de garantir que o número de pods em execução seja igual ao número desejado de pods especificado pelo usuário.

image

kubectl get deployments

apiVersion: apps/v1
kind: Deployment
metadata:
  name: auth
spec:
  selector:
    matchLabels:
      app: auth
  replicas: 1
  template:
    metadata:
      labels:
        app: auth
        track: stable
    spec:
      containers:
        - name: auth
          image: "kelseyhightower/auth:2.0.0"
          ports:
            - name: http
              containerPort: 80
            - name: health
              containerPort: 81
          resources:
            limits:
              cpu: 0.2
              memory: "10Mi"
          livenessProbe:
            httpGet:
              path: /healthz
              port: 81
              scheme: HTTP
            initialDelaySeconds: 5
            periodSeconds: 15
            timeoutSeconds: 5
          readinessProbe:
            httpGet:
              path: /readiness
              port: 81
              scheme: HTTP
            initialDelaySeconds: 5
            timeoutSeconds: 1

Gradual update

Para atualizar sua implantação, execute o seguinte comando:

kubectl edit deployment DEPLOYMENT-NAME

Debug

Entrar em um container dentro de um pod.

kubectl exec --stdin --tty pod-name -- /bin/bash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment