Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
kubectlの基礎
Search
hhiroshell
February 28, 2018
Technology
6
1.1k
kubectlの基礎
hhiroshell
February 28, 2018
Tweet
Share
More Decks by hhiroshell
See All by hhiroshell
Kubernetesでアプリの安定稼働と高頻度のアップデートを両立するためのプラクティス / Best Practices for Applications on Kubernetesto Achieve Both Frequent Updates and Stability
hhiroshell
10
3k
Platform EngineeringにおけるKubernetesの活用法とLINEヤフーにおける事例のご紹介 / Platform Engineering and Kubernetes Findy Lunch LT Edition
hhiroshell
7
1.2k
大規模Webアプリケーションプラットフォームを開発して軌道に乗るまでにやったこと / How to Put Platforms on Track
hhiroshell
2
2.1k
Kubernetesとカスタムコントローラーを活用したプラットフォーム開発・運用の勘所 / Platform Engineering and Kubernetes
hhiroshell
1
790
Best Practices for Applications on Kubernetesto Achieve Both Frequent Updates and Stability
hhiroshell
3
530
Cloud Native Developers JP (cndjp) のご紹介 / about cndjp
hhiroshell
0
140
KustomizeのHash Suffixがあってもいい感じにdiffが見られるkubectlプラグインを作った話 / about kubectl realname-diff
hhiroshell
0
1.4k
JavaアプリをKubernetesで動かすためのチューニングガイド / A tuning guide for running java apps on Kubernetes
hhiroshell
2
3.6k
20,000+行のmanifestをリファクタリングして分かったKustomizeの美しきアーキテクチャと拡張性 / Kustomize deep dive
hhiroshell
5
4.9k
Other Decks in Technology
See All in Technology
カオナビの利用実績をアウトカムへつなげる旅 / example-of-data-management-startup-in-kaonavi
kaonavi
0
110
Databricks における 『MLOps』
databricksjapan
2
130
Janus
bkuhlmann
0
480
シン・Kafka / shin-kafka
oracle4engineer
PRO
6
2.7k
Data and AI Governance: Existing Challenges and Emerging Trends
scotthsieh825
0
140
社内勉強会運営のコツ
senoo
6
1.1k
アプリがつくるNOT A HOTELブランド
hokuts
0
450
長期間TiDBを使ってきた話 @ 私たちはなぜNewSQLを使うのかTiDB選定5社が語る選定理由と活用LT / Experiences with TiDB Over Time
chibiegg
2
580
「共通基盤」を超えよ! 今、Platform Engineeringに取り組むべき理由
jacopen
25
5.7k
ここが嬉しいABAC ここが辛いよABAC #再解説+補足編
masahirokawahara
0
190
Aurora MySQL v3(MySQL8.0互換)の オンラインDDLの罠挙動を全バージョンで検証した
yutakikai
0
150
マルチアカウント環境への発見的統制の導入
ch1aki
1
1.3k
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
501
140k
Statistics for Hackers
jakevdp
789
220k
VelocityConf: Rendering Performance Case Studies
addyosmani
319
23k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
226
16k
Embracing the Ebb and Flow
colly
78
4.1k
A Tale of Four Properties
chriscoyier
150
22k
Designing with Data
zakiwarfel
95
4.8k
Bootstrapping a Software Product
garrettdimon
PRO
301
110k
A better future with KSS
kneath
230
16k
Done Done
chrislema
178
15k
What's in a price? How to price your products and services
michaelherold
237
11k
GraphQLとの向き合い方2022年版
quramy
30
12k
Transcript
Cloud Native Developers JP kubectlの基礎 @hhiroshell 1
Cloud Native Developers JP Kubernetesの全体像 k8sクラスター >_ kubectl (CLI) マシンとネットワーク
2
Cloud Native Developers JP kubectl • Kubernetesクラスターの管理操作を行うためのコマンドラインイン ターフェース • Kubernetesクラスターを操作するときの最も基本的な手段
• コマンドをapiserverが提供するREST APIの呼び出しに変換してい る 3
Cloud Native Developers JP kubectlの設定情報 • kubectlの設定情報の実体は、デフォルトで ~/.kube/config にyaml 形式で保存されている
• kubectl config view とすると現在の設定情報を表示できる • 設定ファイルを明示的に指定して利用したい場合 – kubectlコマンドの --kubeconfig フラグで毎回指定: kubectl get nodes --kubeconfig=~/some_directory/config_file – 環境変数 KUBECONFIG に設定ファイルのパスを設定: export KUBECONFIG=~/some_directory/config_file 4
Cloud Native Developers JP kubectlでよく使うコマンド(チートシート) 5
Cloud Native Developers JP kubectlの接続先クラスターを切り替える • kubectlの設定情報には、複数のクラスターへの接続情報を持てる • kubectl config
use-context <cluster name> で接続先のクラスターを 切り替えることができる 6
Cloud Native Developers JP コマンドの効力が及ぶNamespaceを指定する • Namespaceの一覧を取得するには、kubectl get namespaces •
kubectlのほとんどのコマンドで、効力が及ぶNamespaceを指定す るオプションが使える – すべてのNamespaceを指定するには、--all-namespaces kubectl --all-namespaces get pods – Namespaceの名前を指定するには、--namespace=<namespace-name> kubectl --namespace=mynamespace get pods • デフォルトのNamespaceを変更することも可能 kubectl config set-context $(kubectl config current-context) --namespace=mynamespace 7
Cloud Native Developers JP Kubernetes Objectの情報を取得する • オブジェクトの一覧を取得するには kubectl get
<object type> kubectl get pods kubectl get services • 所定のオブジェクトの詳細情報を取得するには kubectl describe <object type> <object name> kubectl describe pods mypod-1029384756-zxc0x
Cloud Native Developers JP Deploymentを作成する/削除する • kubectl run <deployment name/pod
name prefix> -- image=<image>:<tag> <command> 9
Cloud Native Developers JP manifestファイルでKubernetes Objectを操作する • manifestはKubernetes Objectの構成情報を記述したjson/yamlファイル •
-f オプションでファイル自体のパスか、manifestのあるディレクトリの パスを指定する • 命令的方式 – オブジェクトに対する作用(create, delete, replace...)を明示して実行する kubectl create –f ./deployment-nginx.yaml • 宣言的方式 – maninfestファイルから要求された状態を識別し、自動的にオブジェクトを変更する kubectl apply -f ./deployment-nginx.yaml 10
Cloud Native Developers JP 最もシンプルなmanifestファイルの例 • Podを定義したmanifestの例 – この例では、busyboxというコンテナを含むPodを定義している 11
apiVersion: v1 kind: Pod metadata: name: counter spec: containers: - name: count image: busybox args: [/bin/sh, -c, 'i=0; while true; do echo "$i: $(date)"; i=$((i+1)); sleep 1; done']
Cloud Native Developers JP Podの標準出力/標準エラー出力を表示する • コンソールに表示するには kubectl logs <pod
name> kubectl logs mypod-1029384756-zxc0x • tailするには -f オプション(follow) • kubectl logs -f mypod-1029384756-zxc0x • 所定の時間内の出力を表示するには --since で時間を指定 kubectl logs -f since 1m mypod-1029384756-zxc0x 12
Cloud Native Developers JP 実行中のPodで任意のコマンドを実行する • kubectl exec <pod name>
<command> でOK • “hello world”を出力 kubectl exec mypod-1029384756-zxc0x echo hello world • シェルにアクセス kubectl exec -it mypod-1029384756-zxc0x /bin/bash 13
Cloud Native Developers JP 14 Fin