LoginSignup

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

0904-K8Sのハンズオン手順(For WorkShop)

Last updated at Posted at 2019-09-04

ハンズオン環境ログイン手順

ログインURL

※ログイン用のアカウント情報は、admin/adminとなっています。

受講者No(NN) ログインURL
1 https://
2 https://
3 https://
4 https://
5 https://
6 https://
7 https://
8 https://
9 https://

ログイン手順

・自己署名証明書を利用しています為、ワーニング画面が表示されますが、下記の画面のようにワーニングエラーを無視して接続してください。
image.png

・ユーザーとパスワードを入力してください。
 ※ログイン用のアカウント情報は、admin/adminとなっています。
image.png

・k8sのリンクをクリックし、クラスター画面を開く。
image.png

・kubectlコマンド画面を開く。
image.png
image.png

K8SのWorkloadsのハンズオン

kubectlコマンドとクラスター情報参照

■kubectlコマンド一覧を表示

kubectl:
> kubectl -h
> 

■k8Sのバージョンを参照

kubectl:
> kubectl version
> 

■k8Sのクラスター情報を参照

kubectl:
> kubectl cluster-info
> 

Podリソースの操作

■名前がnginx-podのnginxのPodを作成

apply:
> kubectl run nginx-pod --image=nginx --restart=Never
> 

■Podの詳細情報参照

kubectl get:
> kubectl get pod nginx-pod
NAME        READY   STATUS    RESTARTS   AGE
nginx-pod   1/1     Running   0          113s
> kubectl get pod nginx-pod -o wide
NAME        READY   STATUS    RESTARTS   AGE     IP          NODE                                              NOMINATED NODE   READINESS GATES
nginx-pod   1/1     Running   0          2m15s   10.42.0.7   ip-172-30-1-130.ap-northeast-1.compute.internal   <none>           <none>
> kubectl get pod nginx-pod -o yaml

■Podのイベント情報参照

kubectl get:
> kubectl describe pod nginx-pod

Deploymentリソースの操作(Optional Task)

■nginx-dpのnginxのdeploymentの作成
名前:nginx-dp
Dockerイメージ:--image=nginx:1.14
レプリカ数:--replicas=1

apply:
> kubectl run nginx-dp --image=nginx:1.14 --replicas=1 

■nginx-dpのnginxのdeploymentの参照

get:
> kubectl get deploy nginx-dp      
NAME       READY   UP-TO-DATE   AVAILABLE   AGE
nginx-dp   1/1     1            1           11s
> kubectl get rs
NAME                  DESIRED   CURRENT   READY   AGE
nginx-dp-5fc459f547   1         1         1       4m24s
> kubectl get pod
NAME                        READY   STATUS      RESTARTS   AGE
nginx-dp-5fc459f547-gk5r8   1/1     Running     0          17s
nginx-pod                   0/1     Completed   0          42m 

■nginx-dpのnginxのdeploymentのスケールアウト 
 レプリカ数:--replicas=3

scale:
> kubectl scale --replicas=3 deploy nginx-dp

「■nginx-dpのnginxのdeploymentの参照」手順をもう一回実施

■nginx-dpのnginxのdeploymentのスケールイン レプリカ数:--replicas=1

scale:
> kubectl scale --replicas=1 deploy nginx-dp

「■nginx-dpのnginxのdeploymentの参照」手順をもう一回実施

■nginx-dpのnginxのdeploymentのローリングアップデート

update:
> kubectl set image deployment/nginx-dp nginx-dp=nginx:1.15
> kubectl get deploy nginx-dp -oyaml

■nginx-dpのnginxのdeploymentのロールバック

update:
> kubectl rollout undo deploy nginx-dp
> kubectl get deploy nginx-dp -oyaml

■nginx-dpのnginxのdeploymentの削除

delete:
> kubectl delete deploy nginx-dp
> kubectl get deploy 

Jobリソースの操作(Optional Task - やらなくてもOK)

[Running an example Job]のセクションを実施
https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#running-an-example-job

CronJobリソースの操作(Optional Task - やらなくてもOK)

[Creating a Cron Job]と[Deleting a Cron Job]のセクションを実施
https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#creating-a-cron-job

0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up