Skip to content

Instantly share code, notes, and snippets.

@nenodias
Last active December 21, 2021 11:15
Show Gist options
  • Save nenodias/b40a555125b7ce14a18519465aa58729 to your computer and use it in GitHub Desktop.
Save nenodias/b40a555125b7ce14a18519465aa58729 to your computer and use it in GitHub Desktop.
Kubernetes Helper

List all contexts configured at your computer

kubectl config get-contexts

Define which context you are working

kubectl config use-context


Create

kubectl create -f <FILE_OR_FOLDER>

Apply

kubectl apply -f <FILE_OR_FOLDER>

Delete

kubectl delete -f <FILE_OR_FOLDER>

Enable autoscale of a deployment

kubectl autoscale deployment --cpu-percent=20 --min=1 --max=20


Get Deployments

kubectl get deployment

Get Persistence Storage Claims

kubectl get pvc

Get Services

kubectl get svc

Get Jobs

kubectl get job

Get Pods

kubectl get pods

Show logs from a pod

kubectl logs -t

Show Horizontal Pod Autoscaler

kubectl get hpa

Show metrics (needs metrics-server)

kubectl top pods


Get an url from a minikube service

minikube service --url

Listing the minikube addons

minikube addons list

Enable a minikube addon

minikube addons enable

Minikube with LoadBalance service not work dns

Minikube with NodePor service work dns

Tipos de Serviços

  • ClusterIp serve para comunicação interna dentro do cluster
  • NodePort serve para comunicação interna dentro do cluster e também externa
  • LoadBalancer serve para comunicação externa usando o LoadBalancer do provedor (também funciona como um ClusterIp e NodePort)

Replicaset e Deployment

  • Repliaset permite subir novamente pods que estão dentro do template
  • Deployment permite subir pods como os Replicasets e permitem versionamento e rollback Ex: kubectl rollout undo deployment --to-revision=<versão a ser retornada>

Persistence

  • Volumes tem um ciclo de vida é independente do container mas é vinculado ao pod, é utilizado para compartilhar pastas entre containers de um mesmo pod. (Após a execução o volume é removido, mas os arquivos permanecem no diretório de montagem)
  • Persistents Volumes define um volume (normalmente usado com providers)
  • Persistent Volume Claim (clama por um volume, providers ou local)
  • Storage Classes
  • Statefulsets são deployments fortemente ligados a persistentVolumesClaims que dinamicamente criam os persistentVolumes. Provém garantias sobre o ordenamento e unicidade desses Pods.

Liveness probes

São provas de que a aplicação está viva

  # spec > template > containers
  livenessProbe:
    httpGet:
      path: / #Path of application returning statusCode >= 200 and statusCode < 400
      port: 80 #ContainerPort
    periodSecods: 20 # Each time the kubernetes will test the liveness of the app/pod
    failureThreshold: 3 # How many failures will be accepted before restart the pod
    initialDelaySeconds: 20 # How many time the kubernetes will wait for starting to check health your app                                                                                 

Readiness Probes

São provas de que a aplicação pode receber as chamadas (vem depois do liveness probes) e tem a mesma estrutura.

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