Windows で Docker Desktop その5

[Windows で Docker Desktop その4](https://qiita.com/intrajp/items/5e0df77fb08f61ff4413) からの続きです。

```
PS C:\Users\XXX\TKB\pods> kubectl apply -f init.yml

PS C:\Users\XXX\TKB\pods> kubectl apply -f initsvc.yml
service/k8sbook created
PS C:\Users\XXX\TKB\pods> kubectl get pods --watch
NAME      READY   STATUS     RESTARTS   AGE
initpod   0/1     Init:0/1   0          13m
initpod   0/1     PodInitializing   0          13m
initpod   1/1     Running           0          14m
```

repository をフォークして、ファイルを書き直し、コマンドを実行してみました。

```
PS C:\Users\xxx\TKB\pods> kubectl apply -f initsidecar.yml
pod/git-sync created
service/svc-sidecar created

PS C:\Users\xxx\TKB\pods> kubectl get pods
NAME       READY   STATUS    RESTARTS      AGE
git-sync   2/2     Running   1 (18s ago)   83s
initpod    1/1     Running   0             38m

PS C:\Users\xxx\TKB\pods> kubectl describe pod git-sync
Name:             git-sync
Namespace:        default
Priority:         0
Service Account:  default
Node:             desktop-worker2/172.18.0.4
Start Time:       Sun, 15 Jun 2025 16:55:33 +0900
Labels:           app=sidecar
Annotations:      <none>
Status:           Running
IP:               10.244.2.3
IPs:
  IP:  10.244.2.3
Init Containers:
  ctr-sync:
    Container ID:   containerd://d2a8dca2cbab77227e95fd867bbad3fcb88c26cbde89fbd2939e5659869b093d
    Image:          k8s.gcr.io/git-sync:v3.1.6
    Image ID:       k8s.gcr.io/git-sync@sha256:aa88eb188b3bd4bdd2a4237a4d7be2b8df0cad5be002ad82c13bf47aa2f9bd13
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sun, 15 Jun 2025 16:58:01 +0900
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Sun, 15 Jun 2025 16:56:39 +0900
      Finished:     Sun, 15 Jun 2025 16:57:47 +0900
    Ready:          True
    Restart Count:  2
    Environment:
      GIT_SYNC_REPO:    https://github.com/intrajp/ps-sidecar
      GIT_SYNC_BRANCH:  master
      GIT_SYNC_DEPTH:   1
      GIT_SYNC_DEST:    html
    Mounts:
      /tmp/git from html (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-c69m7 (ro)
Containers:
  ctr-web:
    Container ID:   containerd://ec661b3a3e3b64522facf4e1631d08b8b9e60e6f1152e8dcfa5c7eade6e266b7
    Image:          nginx
    Image ID:       docker.io/library/nginx@sha256:6784fb0834aa7dbbe12e3d7471e69c290df3e6ba810dc38b34ae33d3c1c05f7d
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Sun, 15 Jun 2025 16:55:59 +0900
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /usr/share/nginx/ from html (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-c69m7 (ro)
Conditions:
  Type                        Status
  PodReadyToStartContainers   True
  Initialized                 True
  Ready                       True
  ContainersReady             True
  PodScheduled                True
Volumes:
  html:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
    SizeLimit:  <unset>
  kube-api-access-c69m7:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                  From               Message
  ----     ------     ----                 ----               -------
  Normal   Scheduled  2m43s                default-scheduler  Successfully assigned default/git-sync to desktop-worker2
  Normal   Pulling    2m43s                kubelet            Pulling image "k8s.gcr.io/git-sync:v3.1.6"
  Normal   Pulled     2m32s                kubelet            Successfully pulled image "k8s.gcr.io/git-sync:v3.1.6" in 12.011s (12.011s including waiting). Image size: 61697672 bytes.
  Normal   Pulling    2m31s                kubelet            Pulling image "nginx"
  Normal   Pulled     2m17s                kubelet            Successfully pulled image "nginx" in 13.774s (13.774s including waiting). Image size: 72406859 bytes.
  Normal   Created    2m17s                kubelet            Created container ctr-web
  Normal   Started    2m17s                kubelet            Started container ctr-web
  Warning  BackOff    28s                  kubelet            Back-off restarting failed container ctr-sync in pod git-sync_default(f4d8fb0b-12e9-44cd-a34c-34ace7068cb4)
  Normal   Created    15s (x3 over 2m32s)  kubelet            Created container ctr-sync
  Normal   Started    15s (x3 over 2m32s)  kubelet            Started container ctr-sync
  Normal   Pulled     15s (x2 over 97s)    kubelet            Container image "k8s.gcr.io/git-sync:v3.1.6" already present on machine
  
PS C:\Users\xxx\TKB\pods> kubectl get svc svc-sidecar
NAME          TYPE           CLUSTER-IP     EXTERNAL-IP   PORT(S)        AGE
svc-sidecar   LoadBalancer   10.96.102.57   172.18.0.7    80:30126/TCP   5m8s
```

webページにアクセスしてみます。

```
PS C:\Users\xxx\TKB\pods> curl http://localhost


StatusCode        : 200
StatusDescription : OK
Content           : <!DOCTYPE html>
                    <html>
                    <head>
                    <title>NGINX</title>
                    <style>
                        body {
                            width: 35em;
                            margin: 0 auto;
                            font-family: Tahoma, Verdana, Arial, sans-serif;
                        }
                    </style>
                    </head>
                    <body...
RawContent        : HTTP/1.1 200 OK
                    Connection: keep-alive
                    Accept-Ranges: bytes
                    Content-Length: 247
                    Content-Type: text/html
                    Date: Sun, 15 Jun 2025 08:05:58 GMT
                    ETag: "684e7c82-f7"
                    Last-Modified: Sun, 15 Jun 2025 0...
Forms             : {}
Headers           : {[Connection, keep-alive], [Accept-Ranges, bytes], [Content-Length, 247], [Content-Type, text/html]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 247
```

![スクリーンショット 2025-06-15 171013.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/470368/7ddf2e9a-5e8a-4644-a8fd-8570bb8b3366.png)

[Windows で Docker Desktop その6](https://qiita.com/intrajp/items/3fd89f648dbc17547498)に続く。

参考文献

Poulton, N. (2025). The kubernetes book (2025 ed.). Nigel Poulton.