tjtjtjのメモ

自分のためのメモです

kubernetes 学習 nginx pod 作成

kb1 nginx pod 作成

$ kubectl get pods
No resources found.
$ kubectl run nginx --image=nginx:1.15.8
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/nginx created
$ kubectl get pods
NAME                     READY   STATUS              RESTARTS   AGE
nginx-694b4b8479-swzm2   0/1     ContainerCreating   0          12s
$ kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-694b4b8479-swzm2   1/1     Running   0          21s
$ kubectl get deployment
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   1/1     1            1           2m40s

ロードバランサ 作成

$ kubectl get service
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      10.96.0.1       <none>        443/TCP        2d22h
$ kubectl expose deployment nginx --port 80 --type LoadBalancer
service/nginx exposed
$ kubectl get service
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      10.96.0.1       <none>        443/TCP        2d22h
nginx        LoadBalancer   10.107.27.81   <pending>     80:30635/TCP   4s

確認

$ curl 10.107.27.81
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

お掃除

ロードバランサ service 削除。

$ kubectl get service
NAME         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP      10.96.0.1       <none>        443/TCP        2d22h
nginx        LoadBalancer   10.103.26.220   <pending>     80:31747/TCP   13s
$ kubectl delete service nginx
service "nginx" deleted
$ kubectl get service
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.96.0.1    <none>        443/TCP   2d23h

nginx pod 削除。deployment を削除して pod が消えるのを待つ。

$ kubectl get deployment
NAME    READY   UP-TO-DATE   AVAILABLE   AGE
nginx   1/1     1            1           3m41s
$ kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
nginx-86f6c4996d-s77wf   1/1     Running   0          3m47s
$ kubectl delete deployment nginx
deployment.extensions "nginx" deleted
$ kubectl get deployment
No resources found.
$ kubectl get pods
No resources found.