The Kubernetes Book
Common tasks with kubernetes
How to apply a deployment using kubectl
$ kubectl apply -f posts.yaml
How to see what pods are running in your cluster
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
posts 1/1 Running 0 5m24s
$
How to see what files are inside your pod
$ kubectl exec posts -- ls
index.js
node_modules
package-lock.json
package.json
$
How to see the logs for your pod
$ kubectl logs posts
> posts@1.0.0 start:docker
> nodemon index.js
[nodemon] 2.0.6
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node index.js`
[posts] running on port 3001
$
How to delete a pod
$ kubectl delete pod posts
pod "posts" deleted
$
How to apply a deployment file
$ kubernetes apply -f posts-depl.yaml
How to delete a deployment
$ kubernetes delete deployment posts-depl
How to get a list of deployments
$ kubernetes get deployments
How to get a description of a deployment
$ kubernetes describe deployment posts-depl
How to update a deployment
(1) Update the code in your microservice
What are the different types of Service objects?

How to access a pod from outside of a cluster
apiVersion: v1
kind: Service
metadata:
name: posts-srv
spec:
type: NodePort
selector:
app: posts
ports:
- name: posts
protocol: TCP
port: 3001
targetPort: 3001
Last updated