How to apply a deployment using kubectl
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
$
$ kubectl delete pod posts
pod "posts" deleted
$
How to apply a deployment file
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
// (1) replace the hard-coded "version" with "latest" i.e.
BEFORE
image: debugme/posts:x:y:z
AFTER
image: debugme/posts:latest
$ docker build . -t debugme/posts:latest
$ docker push debugme/posts:latest
$ kubectl rollout restart deployment posts-depl
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
$ kubectl apply -f ../infra/k8s/posts-srv.yaml
$ kubectl describe service posts-srv
Name: posts-srv
Namespace: default
Labels: <none>
Annotations: <none>
Selector: app=posts
Type: NodePort
IP: 10.106.229.229
LoadBalancer Ingress: localhost
Port: posts 3001/TCP
TargetPort: 3001/TCP
NodePort: posts 30159/TCP 👈👈👈👈👈👈
Endpoints: 10.1.0.22:3001
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
// browser
http://localhost:30159/posts
// postman
GET http://localhost:30159/posts