0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Minikube 上でのkubectlコマンド実行など (Windows 10)

Last updated at Posted at 2019-07-22
  • VirtualBoxのインストール (6.0.8 r130520 (Qt5.6.2))

  • namespace 作成

kubectl create namespace [namespace]

  • commandのみでnginx imageのpodを作成する
kubectl run nginx --image=nginx --restart=Never --namespace=mynamespace


(**) option 説明
--restart=Never : podが存在するときrestartしない

  • commandから作成したpodを削除する
kubectl delete pod [pod name] -n [namespace]

  • Yaml fileを作成してpodを作成する
kubectl run nginx --image=nginx  --restart=Never   --namespace=mynamespace --dry
-run -o yaml > nginx.yaml
kubectl create -f nginx.yaml --namespace=mynamespace

(**) option説明
--dry-run : command実行しない
-o yaml : yaml形式で
上記2つのoptionを組み合わせることで、run 実行するための
yamlファイルが取得できる。


以下のようなファイルをviなどで作成してもOK

vi pod-nginx
===
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  containers:
  - image: nginx
    name: nginx
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}
===

kubectl create -f nginx.yaml --namespace=mynamespace


  • pod名:bb でbusybox imageのPodを作成し、"env" コマンドの実行結果を標準出力に表示する。
kubectl run bb --image=busybox --namespace=mynamespace --restart=Never --tty -it --command -- env --namespace=mynamespace

(**) 実行結果
===
PS C:\kubernetes> kubectl run bb --image=busybox --namespace=mynamespace --restart=Never --tty -it
 --command -- env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=bb
TERM=xterm
KUBERNETES_PORT=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP=tcp://10.96.0.1:443
KUBERNETES_PORT_443_TCP_PROTO=tcp
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=10.96.0.1
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443
KUBERNETES_SERVICE_PORT_HTTPS=443
HOME=/root
===
  • NameSpace 'myns' を作成するためのYaml codeを取得する。
> kubectl.exe create namespace myns --dry-run -o yaml
apiVersion: v1
kind: Namespace
metadata:
  creationTimestamp: null
  name: myns
spec: {}
status: {}

  • ResourceQuota 'myrq' を作成するためのyaml codeを取得する。
> kubectl.exe create resourcequota myrq --dry-run -o yaml
apiVersion: v1
kind: ResourceQuota
metadata:
  creationTimestamp: null
  name: myrq
spec: {}
status: {}

  • すべてのNameSpaceのPodを表示する。
> kubectl.exe get pods --all-namespaces
NAMESPACE     NAME                                    READY   STATUS      RESTARTS   AGE
kube-system   coredns-5c98db65d4-dtqm6                1/1     Running     2          3d
kube-system   coredns-5c98db65d4-kx9mz                1/1     Running     2          3d
kube-system   etcd-minikube                           1/1     Running     1          3d
kube-system   kube-addon-manager-minikube             1/1     Running     1          3d
kube-system   kube-apiserver-minikube                 1/1     Running     1          3d
kube-system   kube-controller-manager-minikube        1/1     Running     1          3d
kube-system   kube-proxy-hvnh6                        1/1     Running     1          3d
kube-system   kube-scheduler-minikube                 1/1     Running     1          3d
kube-system   kubernetes-dashboard-7b8ddcb5d6-7dvx7   1/1     Running     2          3d
kube-system   storage-provisioner                     1/1     Running     2          3d
mynamespace   bb                                      0/1     Completed   0          18m
mynamespace   nginx                                   1/1     Running     0          86m
  • image : nginx の pod nginxを作成しport 80へのトラフィックを許可する。
kubectl.exe run nginx --image=nginx --restart=Never --namespace=mynamespace --po
rt=80
  • 稼働中のpod:nginxのimageをnginx:1.7.1に更新する
kubectl.exe set image pod nginx nginx=nginx:1.7.1 --namespace=mynamespace

===
> kubectl.exe set image pod nginx nginx=nginx:1.7.1 --namespace=mynamespace^C
PS C:\Users\tsutomu.tazawa\kubernetes> kubectl.exe describe pod nginx --namespace=mynamespace
Name:         nginx
Namespace:    mynamespace
Priority:     0
Node:         minikube/10.0.2.15
Start Time:   Mon, 22 Jul 2019 13:03:34 +0900
Labels:       run=nginx
Annotations:  <none>
Status:       Running
IP:           172.17.0.6
Containers:
  nginx:
    Container ID:   docker://c030cf10cc621edcc6f79b2e6905c1c0659a3753f5b9b3aff3052fbf1866cb0c
    Image:          nginx:1.7.1
    Image ID:       docker-pullable://nginx@sha256:7fbe0579e123f3d2b29c9159e9a80547fb72621bb419e52d98c679ddbf1055a1
    Port:           80/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Mon, 22 Jul 2019 16:35:50 +0900
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Mon, 22 Jul 2019 13:03:38 +0900
      Finished:     Mon, 22 Jul 2019 16:35:47 +0900
    Ready:          True
    Restart Count:  1
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-pstnz (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-pstnz:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-pstnz
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason   Age                  From               Message
  ----    ------   ----                 ----               -------
  Normal  Killing  66s                  kubelet, minikube  Container nginx definition changed, will be restarted
  Normal  Pulling  66s                  kubelet, minikube  Pulling image "nginx:1.7.1"
  Normal  Created  63s (x2 over 3h33m)  kubelet, minikube  Created container nginx
  Normal  Started  63s (x2 over 3h33m)  kubelet, minikube  Started container nginx
  Normal  Pulled   63s                  kubelet, minikube  Successfully pulled image "nginx:1.7.1"
===



[参考資料]
-- kubernetes : kubectlコマンド一覧
https://qiita.com/suzukihi724/items/241f7241d297a2d4a55c

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?