Last active
May 8, 2018 20:33
-
-
Save vitor-caetano/a217ce7cc16fac4aae21dcaf284823ce to your computer and use it in GitHub Desktop.
Kubernets commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| minikube version | |
| minikube start | |
| minikube start --vm-driver=virtualbox | |
| minikube status | |
| kubectl version | |
| kubectl cluster-info | |
| kubectl get componentstatuses | |
| kubectl get events | |
| kubectl get pods --all-namespaces | |
| kubectl get services --all-namespaces | |
| $ docker login quay.io | |
| kubectl run flask --image=quay.io/kubernetes-for-developers/flask --port=5000 --save-config | |
| deployment.apps "flask" created | |
| kubectl get deployments | |
| kubectl get deployment flask -o json | |
| $ kubectl get replicaset | |
| $ kubectl get pods | |
| NAME READY STATUS RESTARTS AGE | |
| flask-6b79cdfc78-prjsx 1/1 Running 0 18s | |
| $ kubectl port-forward flask-84f75f46d4-lsxp7 5000:5000 | |
| open 'http://localhost:5000/' | |
| CTRL+C | |
| kubectl proxy | |
| kubectl logs flask-84f75f46d4-lsxp7 | |
| $ kubectl delete deployment flask | |
| deployment.extensions "flask" deleted | |
| $ kubectl get deployments | |
| No resources found. | |
| kubectl run nodejs --image=quay.io/kubernetes-for-developers/nodejs:0.2.0 --port=3000 | |
| kubectl run --help | |
| kubectl run -i -t alpine-interactive --image=alpine -- sh | |
| kubectl run -i -t python-interactive --image=quay.io/kubernetes-for-developers/flask:latest --command -- /bin/sh | |
| kubectl run nodejs --image=quay.io/kubernetes-for-developers/nodejs:0.2.0 --port=3000 | |
| $ kubectl get pods | |
| NAME READY STATUS RESTARTS AGE | |
| nodejs-5b985b9776-542c9 1/1 Running 0 3m | |
| $ kubectl exec nodejs-5b985b9776-542c9 -it -- /bin/sh | |
| /src # | |
| echo Aliasing tools | |
| alias mk='/usr/local/bin/minikube' | |
| alias k='kubectl' | |
| k describe deployment nodejs | |
| echo Filtering labels | |
| k get pods -l run=nodejs | |
| echo Shown columns labels | |
| k get pods -L run | |
| k get pods -L run,pod-template-hash | |
| k run flask --image=quay.io/kubernetes-for-developers/flask:latest | |
| k describe deployment flask | |
| k describe replicaset flask | |
| k describe pod flask | |
| echo Create a service based on a resource that is already operating within the cluster | |
| $ k expose deploy flask --port 5000 | |
| service "flask" exposed | |
| $ k get services | |
| NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE | |
| flask ClusterIP 10.100.231.71 <none> 5000/TCP 52s | |
| kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 7d | |
| k describe service flask | |
| $ k exec flask-7bdd449f7f-hxk64 -it -- /bin/sh | |
| / # env | |
| KUBERNETES_PORT=tcp://10.96.0.1:443 | |
| KUBERNETES_SERVICE_PORT=443 | |
| HOSTNAME=flask-7bdd449f7f-hxk64 | |
| SHLVL=1 | |
| HOME=/root | |
| TERM=xterm | |
| KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1 | |
| PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin | |
| KUBERNETES_PORT_443_TCP_PORT=443 | |
| KUBERNETES_PORT_443_TCP_PROTO=tcp | |
| KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443 | |
| KUBERNETES_SERVICE_PORT_HTTPS=443 | |
| PWD=/ | |
| KUBERNETES_SERVICE_HOST=10.96.0.1 | |
| echo Creating NodePort service | |
| k expose deploy flask --port 5000 --type=NodePort | |
| k get service flask -o yaml | |
| telnet $(minikube ip) 31855 | |
| $ minikube service flask --url | |
| http://192.168.99.100:31855 | |
| echo Openning service on default browser | |
| $ minikube service flask | |
| Opening kubernetes service default/flask in default browser... | |
| $ minikube service list | |
| |-------------|----------------------|-----------------------------| | |
| | NAMESPACE | NAME | URL | | |
| |-------------|----------------------|-----------------------------| | |
| | default | flask | http://192.168.99.100:31855 | | |
| | default | kubernetes | No node port | | |
| | kube-system | default-http-backend | http://192.168.99.100:30001 | | |
| | kube-system | kube-dns | No node port | | |
| | kube-system | kubernetes-dashboard | http://192.168.99.100:30000 | | |
| |-------------|----------------------|-----------------------------| | |
| $ kubectl run redis --image=docker.io/redis:alpine | |
| deployment.apps "redis" created | |
| $ k get pods | |
| NAME READY STATUS RESTARTS AGE | |
| flask-7bdd449f7f-spj5q 1/1 Running 0 19m | |
| redis-84bc6bb5db-ws468 1/1 Running 0 36s | |
| $ k exec -it redis-84bc6bb5db-ws468 -- /bin/sh | |
| /data # ps aux | |
| PID USER TIME COMMAND | |
| 1 redis 0:00 redis-server | |
| 13 root 0:00 /bin/sh | |
| 17 root 0:00 ps aux | |
| /data # which redis-server | |
| /usr/local/bin/redis-server | |
| /data # redis-server --version | |
| Redis server v=4.0.9 sha=00000000:0 malloc=jemalloc-4.0.3 bits=64 build=cce7cc41d26597f7 | |
| /data # exit | |
| $ kubectl expose deploy redis --port=6379 --type=NodePort | |
| service "redis" exposed | |
| $ k get pods | |
| NAME READY STATUS RESTARTS AGE | |
| flask-7bdd449f7f-spj5q 1/1 Running 0 28m | |
| redis-84bc6bb5db-ws468 1/1 Running 0 9m | |
| $ k exec flask-7bdd449f7f-spj5q -it -- sh | |
| / # nslookup redis.default | |
| nslookup: can't resolve '(null)': Name does not resolve | |
| Name: redis.default | |
| Address 1: 10.101.252.188 redis.default.svc.cluster.local | |
| / # | |
| kubectl get deploy flask -o yaml --export > flask_deployment.yaml | |
| kubectl replace -f flask_deployment.yaml | |
| deployment "flask" replaced | |
| kubectl rollout status deployment/flask | |
| kubectl rollout history deployment/flask | |
| minikube delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment