---
# System prepended metadata

title: Kubernetes basic commands

---

# Kubernetes basic commands



## Install gcloud first


[Install gcloud from here](https://cloud.google.com/sdk/docs/install)



### Add appropiate cluster

Exmaple: Add staging cluster
```
gcloud container clusters get-credentials p-stage --zone zone_name --project project_name
```

## Access the cluster

### Get pods

```
kubectl get pods -n NAMESPACE
```

### Get deployments

```
kubectl get deployments -n NAMESPACE
```

### Get services

```
kubectl get services -n NAMESPACE
```


### Check log
```
kubectl logs -f -n NAMESPACE POD_NAME
```


### Access pod
```
kubectl exec -it -n NAMESPACE POD_NAME  -- /bin/sh
```

### Port forward

```
kubectl port-forward -n NAMESPACE POD/SERVICE_NAME TO_PORT:FROM_PORT
```
