---
# System prepended metadata

title: Kubernete Helper

---

# Kubernete Helper

[Notion](https://www.notion.so/jusbrasil/Kubernetes-63bf1083f9b44888ade0a3ae246fd036#7dcecf3ec2a34305855347a008c0f5e1)

[Introduction](https://aws.plainenglish.io/introduction-to-kubernetes-850907f54627)

[Archtecture](https://aws.plainenglish.io/kubernetes-architecture-c93cb9c798d8)

[Troubleshooting](https://learnk8s.io/troubleshooting-deployments)

## Options

### Watch mode
    -w

### Namescape

#### Show you current default namespace (empty=default)
    kl config view --minify | grep namespace:
#### Config you default namespace
    kl config set-context --current --namespace=<insert-namespace-name-here>
#### Run commands with selected namespace
    -n <namespace>
    
##### to select all namespaces: 
    --all-namespaces
    
### Additional variable envs
    --additional_env_vars VAR_NAME=content

## Show components

### List:
    kl get pod
    kl get pod | grep <filter-by-name>
    kl get services
    kl get statefulSets
    kl get deployments
    kl get nodes
    kl get namespaces
    kl get cronjobs
    kl get jobs

### Describe details 
    kl describe pod <pod-name>
    kl describe service <service-name>
    kl describe deployment <service-name>
    kl describe node <node-name>

### Show logs
    kl logs -f <pod-name> 
    kl logs -f <pod-name> | grep <filter>
    kl logs -f -l <label-name>=<label>
#### Attach
    kl attach -it <pod-name>

## Copy files
    kl cp <pod>:<filename> <dest-dir> -n <namespace>

## Deploy management

#### Create a new pod
    kl batch <service-name> bash
    kl exec -it <service-name> bash
    
#### Restart deployment
    kl rollout restart deployment/<deployment-name>

#### Rollback deployment
    kl rollout undo deploy <deployment-name>
    kl rollout undo deploy <deployment-name> --to-revision=3    

    kl rollout history deploy <deployment-name>
    kl rollout history deploy <...> --revision=<revision-number> | grep Image:
    kl set image deploy/nginx-kube 'nginx=$VERSION'
    kl rollout status deployment/<name> -n <namespace>


#### Delete
    kl delete pod <pod-name>
    kl delete service <deployment-name>
    kl delete deployments <deployment-name>
    kl delete deployments,service <name> --namespace=development
    
### Scale

#### update scales by xml
    kl edit deployment <deployment>

#### Update keda (autoscale)

###### Change maxReplicaCount and minReplicaCount
    kl edit scaledobject.keda.sh <deployment>

#### Force autoscale
    kl scale

#### Change replicas count
    kl scale --replicas=8 deploy/<deployment>

### Port forwarding
    kl pf <pod> PORT:TARGET
    
### Configuration management

###### create new component
    kl create -f <component>.yaml 

###### update component 
    kl apply -f <component>.yaml
    
### Cronjob

##### Force run a cronjob:
    kl create job --from=cronjob/<cronjob-name> <cronjob-name-@dev> -n <namespace>