Overview of “kubectl”. Kubernetes commands.
Requires:
1. Установить kubectl и авторизоваться для доступа google cloud clusters
2. Сlusters get credentials
$ gcloud container clusters get-credentials cluster-u4u-develop --zone europe-west1-c
https://cloud.google.com/sdk/gcloud/reference/container/clusters/get-credentials
3. Enabling shell autocompletion
$ echo "source <(kubectl completion bash)" >> ~/.bashrc
https://kubernetes.io/docs/tasks/tools/install-kubectl/#enabling-shell-autocompletion
Примеры комманд.
Переключение между кластерами
➜ k8s git:(airat) ✗ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
develop_u4u_project_gitlab develop_u4u_project gitlab default
gke_u4u-project_europe-west1-c_cluster-u4u-develop gke_u4u-project_europe-west1-c_cluster-u4u-develop gke_u4u-project_europe-west1-c_cluster-u4u-develop
minikube minikube minikube
* production_u4u_project_gitlab gke_u4u-project_europe-west1-c_cluster-u4u-production gittlab_prod production
➜ k8s git:(airat) ✗ kubectl config use-context gke_u4u-project_europe-west1-c_cluster-u4u-develop
Switched to context "gke_u4u-project_europe-west1-c_cluster-u4u-develop".
➜ k8s git:(airat) ✗
➜ k8s git:(airat) ✗
➜ k8s git:(airat) ✗ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
develop_u4u_project_gitlab develop_u4u_project gitlab default
* gke_u4u-project_europe-west1-c_cluster-u4u-develop gke_u4u-project_europe-west1-c_cluster-u4u-develop gke_u4u-project_europe-west1-c_cluster-u4u-develop
minikube minikube minikube
production_u4u_project_gitlab gke_u4u-project_europe-west1-c_cluster-u4u-production gittlab_prod production
➜ k8s git:(airat) ✗
Ролучить информацию о запущенных контейнерах (pods in kubernetes)
$ kubectl get pod
Чтоб в “реальном времени” следить за изменениями состояния контейнеров. (pods in kubernetes)
$ watch kubectl get pod
Output:
NAME READY STATUS RESTARTS AGE
auth-667477fdf8-s7wcp 1/1 Running 0 4d
front-5cd6748bc8-rkpcc 1/1 Running 0 16h
genpdf-5f4bd9d954-vsls9 1/1 Running 0 4d
kong-77784c9947-pm4df 1/1 Running 0 3d
mongodb-67f6d8c858-4879z 1/1 Running 0 4d
order-5f4c58f7d7-rr98l 1/1 Running 0 4d
photod-6894858877-rvlzw 1/1 Running 0 4d
photorec-847448d89f-5fknw 1/1 Running 0 4d
postgresql-854db4dcb7-vx85x 1/1 Running 1 4d
promo-fb66c7b84-p6f2t 1/1 Running 0 4d
rabbitmq-0 1/1 Running 0 4d
redis-master-0 1/1 Running 1 4d
textgen-8645fc845b-xfx57 1/1 Running 0 4d
tsm-77f799cf5-v6rl6 1/1 Running 7 4d
ua-d694bf874-sqfg9 1/1 Running 0 4d
wa-98dbc4cbf-w5hjj 1/1 Running 0 4d
Удалить контейнер(pods in kubernetes)
$ kubectl delete pod front-5cd6748bc8-rkpcc
Логирвание сервиса
$ kubectl logs -f kong-77784c9947-pm4df
Получить bash запущенного контейнера
$ kubectl exec -it genpdf-5f4bd9d954-vsls9 -- /bin/bash
Получить актуальное название docker images
$ watch kubectl get deploy -o wide
Output:
Every 2,0s: kubectl get deploy -o wide webdev: Wed May 30 18:49:48 2018
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
auth 1 1 1 1 13d auth center.u4u.online/auth:latest app=auth,release=develop-u4u
develop-gitlab-runner-gitlab-runner 1 1 1 1 6d develop-gitlab-runner-gitlab-runner gitlab/gitlab-runner:alpine-v10.3.0 app=develop-gitlab-runner-gitlab-runner
front 1 1 1 1 13d front center.u4u.online/front:promo_multi app=front,release=develop-u4u
genpdf 1 1 1 1 13d genpdf center.u4u.online/genpdf:latest app=genpdf,release=develop-u4u
kong 1 1 1 1 13d kong center.u4u.online/kong-new2:latest app=kong,release=develop-u4u
mongodb 1 1 1 1 13d develop-u4u-mongodb docker.io/mongo:3.3 app=mongodb
order 1 1 1 1 13d order center.u4u.online/order:220_promo_several_products_fuso app=order,release=develop-u4u
photod 2 2 2 2 13d photod center.u4u.online/photod:latest app=photod,release=develop-u4u
photorec 2 2 2 2 13d photorec center.u4u.online/photorec:latest app=photorec,release=develop-u4u
postgresql 1 1 1 1 13d postgresql postgres:9.6.2 app=postgresql
promo 1 1 1 1 13d promo center.u4u.online/promo:220_promo_several_products app=promo,release=develop-u4u
textgen 1 1 1 1 13d textgen center.u4u.online/textgen:latest app=textgen,release=develop-u4u
tsm 2 2 2 2 13d tsm center.u4u.online/tsm:latest app=tsm,release=develop-u4u
ua 1 1 1 1 13d ua center.u4u.online/ua:latest app=ua,release=develop-u4u
wa 1 1 1 1 13d wa center.u4u.online/wa:latest app=wa,release=develop-u4u
The package manager for Kubernetes
no changes added to commit (use "git add" and/or "git commit -a")
➜ k8s git:(220_promo_several_products) ✗ pwd
/home/airat/PycharmProjects/k8s
Error: unknown command "ll" for "helm"
Run 'helm --help' for usage.
➜ k8s git:(220_promo_several_products) ✗ helm ls
NAME REVISION UPDATED STATUS CHART NAMESPACE
develop-gitlab-runner 1 Thu May 24 13:48:43 2018 DEPLOYED gitlab-runner-0.1.16 default
develop-u4u 30 Wed May 30 18:18:15 2018 DEPLOYED u4u-0.1.1 default
➜ k8s git:(220_promo_several_products) ✗
➜ k8s git:(220_promo_several_products) ✗
➜ k8s git:(220_promo_several_products) ✗ helm upgrade develop-u4u u4u
Overview of kubectl
https://kubernetes.io/docs/reference/kubectl/overview/