Lead Software Engineer @ProtoPie
Microsoft MVP
TypeScript Korea User Group Organizer
Marktube (Youtube)
이 웅재
~/Desktop/kubernets
➜ docker run busybox echo "Hello world"
Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
9758c28807f2: Pull complete
Digest: sha256:a9286defaba7b3a519d585ba0e37d0b2cbee74ebfe590960b0b1d6a5e97d1e1d
Status: Downloaded newer image for busybox:latest
Hello world
FROM node:12.19.0-alpine
LABEL maintainer="mark@protopie.io"
WORKDIR /app
RUN apk update && apk add python g++ make && rm -rf /var/cache/apk/*
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 5000
ENTRYPOINT ["node", "src/server"]
~/Desktop/kubernets took 5s
➜ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xt13 latest 7332d5c74af6 11 hours ago 384MB
xt12 latest 366f83336186 11 hours ago 384MB
<none> <none> 771fdf38bf8a 11 hours ago 330MB
xt11 latest 14918f9ef7a0 11 hours ago 386MB
xt10 latest 75e57f8e9f7a 12 hours ago 386MB
xt9 latest b474ffeb5c34 12 hours ago 391MB
xt7 latest 39b757fe2fae 12 hours ago 150MB
xt6 latest 3048cde361ed 12 hours ago 149MB
xt5 latest 90dc2439ab42 15 hours ago 150MB
xt4 latest 67ee4668259a 15 hours ago 356MB
<none> <none> 316408239a83 15 hours ago 90.9MB
<none> <none> 13331780c606 15 hours ago 90.9MB
xt3 latest 94aa35c5a04b 15 hours ago 357MB
<none> <none> 9fe751434a46 15 hours ago 90.9MB
xt1 latest ff5f72d932c9 15 hours ago 134MB
<none> <none> 8065142b9016 16 hours ago 134MB
v7 latest 1855016c214f 6 days ago 96.7MB
v6 latest d834ecf2e4fa 6 days ago 96.7MB
v5 latest c2df0c55043c 6 days ago 96.7MB
...
~/Desktop/kubernets
➜ docker run --name nginx-container -p 80:80 -d nginx
Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
bb79b6b2107f: Pull complete
111447d5894d: Pull complete
a95689b8e6cb: Pull complete
1a0022e444c2: Pull complete
32b7488a3833: Pull complete
Digest: sha256:ed7f815851b5299f616220a63edac69a4cc200e7f536a56e421988da82e44ed8
Status: Downloaded newer image for nginx:latest
879e99997b0b0c88fb2295cbef9de0ede651e935acf86de19b536a48ce235e69
~/Desktop/kubernets
➜ curl localhost
<!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>
~/Desktop/kubernets took 15s
➜ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
879e99997b0b nginx "/docker-entrypoint.…" 57 seconds ago Up 56 seconds 80/tcp, 0.0.0.0:80->80/tcp nginx-container
~/Desktop/kubernets
➜ docker inspect nginx-container
[
{
"Id": "879e99997b0b0c88fb2295cbef9de0ede651e935acf86de19b536a48ce235e69",
"Created": "2020-10-27T05:35:22.5560472Z",
"Path": "/docker-entrypoint.sh",
"Args": [
"nginx",
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 79854,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-10-27T05:35:22.9538582Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:f35646e83998b844c3f067e5a2cff84cdf0967627031aeda3042d78996b68d35",
"ResolvConfPath": "/var/lib/docker/containers/879e99997b0b0c88fb2295cbef9de0ede651e935acf86de19b536a48ce235e69/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/879e99997b0b0c88fb2295cbef9de0ede651e935acf86de19b536a48ce235e69/hostname",
"HostsPath": "/var/lib/docker/containers/879e99997b0b0c88fb2295cbef9de0ede651e935acf86de19b536a48ce235e69/hosts",
"LogPath": "/var/lib/docker/containers/879e99997b0b0c88fb2295cbef9de0ede651e935acf86de19b536a48ce235e69/879e99997b0b0c88fb2295cbef9de0ede651e935acf86de19b536a48ce235e69-json.log",
"Name": "/nginx-container",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"8080/tcp": [
{
"HostIp": "",
"HostPort": "8080"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Capabilities": null,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": null,
"DeviceRequests": null,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": null,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/var/lib/docker/overlay2/7b1c9cb31a5086141fad1ef82e6b9eee1d09d0b9434ae183f75451050bc17165-init/diff:/var/lib/docker/overlay2/91393c9d4b2b25d4f3c3106ee086ff6fa3edc8a0877078d64032108269b03e83/diff:/var/lib/docker/overlay2/6c27ab6692cb5adefa3635e2fcb2d37f1fc7aaf74bd704178d8b35ef9c1da46d/diff:/var/lib/docker/overlay2/0da4dfcf1134dc0a8601cbfe4b73476640d0e80a2603331d7f44475cef5fa349/diff:/var/lib/docker/overlay2/cad41dd4c6761888dd1974bb4057c00c6cb5abb8520af5ef77697f19e1b2ff81/diff:/var/lib/docker/overlay2/1b67443eaa3cd63d9f46e1a62fc86636c60517b85036d4994427a14e0e8a51cd/diff",
"MergedDir": "/var/lib/docker/overlay2/7b1c9cb31a5086141fad1ef82e6b9eee1d09d0b9434ae183f75451050bc17165/merged",
"UpperDir": "/var/lib/docker/overlay2/7b1c9cb31a5086141fad1ef82e6b9eee1d09d0b9434ae183f75451050bc17165/diff",
"WorkDir": "/var/lib/docker/overlay2/7b1c9cb31a5086141fad1ef82e6b9eee1d09d0b9434ae183f75451050bc17165/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "879e99997b0b",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {},
"8080/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.19.3",
"NJS_VERSION=0.4.4",
"PKG_RELEASE=1~buster"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"Image": "nginx",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": [
"/docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
},
"StopSignal": "SIGTERM"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "3367f2a1a3a7e9f841624a9591d2fd6f2f2c274a14e3422b4fe7a816f401203f",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": null,
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
]
},
"SandboxKey": "/var/run/docker/netns/3367f2a1a3a7",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "da57917c22494188aa4c98a3daedb8289633c207f341a1c51b633ae3ba06056a",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "3fe6b85a96405f1c979d07cd1dcc72ba598328b93de0343035ebcd916d8d6507",
"EndpointID": "da57917c22494188aa4c98a3daedb8289633c207f341a1c51b633ae3ba06056a",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
~/Desktop/kubernets
➜ docker exec -it nginx-container bash
root@8b02e823d3a4:/#
~/Desktop/kubernets took 2m 52s
➜ docker stop nginx-container
nginx-container
~/Desktop/kubernets
➜ docker rm nginx-container
nginx-container
~/Desktop/kubernets took 2m 52s
➜ docker tag nginx mark/nginx
~/Desktop/kubernets
➜ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
mark/nginx latest f35646e83998 13 days ago 133MB
~/Desktop/kubernets
➜ docker push mark/nginx
# Minikube 란 ??
로컬에서
쿠버네티스를 테스트하고 애플리케이션을 개발하는 목적으로
단일 노드 클러스터를 설치하는
도구다.
- https://kubernetes.io/ko/docs/tasks/tools/install-minikube/
~/Desktop/kubernets
➜ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-amd64 \
&& chmod +x minikube
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 53.0M 100 53.0M 0 0 65.2M 0 --:--:-- --:--:-- --:--:-- 65.2M
~/Desktop/kubernets
➜ ll
total 338192
-rwxr-xr-x 1 mark staff 53M 10 27 09:37 minikube
-rw-r--r--@ 1 mark staff 99M 9 10 12:33 쿠버네티스인액션.pdf
~/Desktop/kubernets
➜ ./minikube status
🤷 There is no local cluster named "minikube"
👉 To fix this, run: "minikube start"
~/Desktop/kubernets
➜ ./minikube start
😄 Darwin 10.15.7 위의 minikube v1.14.1
✨ 자동적으로 docker 드라이버가 선택되었습니다
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
💾 Downloading Kubernetes v1.19.2 preload ...
> preloaded-images-k8s-v6-v1.19.2-docker-overlay2-amd64.tar.lz4: 486.33 MiB
🔥 Creating docker container (CPUs=2, Memory=1990MB) ...
🐳 쿠버네티스 v1.19.2 을 Docker 19.03.8 런타임으로 설치하는 중
🔎 Verifying Kubernetes components...
🌟 Enabled addons: storage-provisioner, default-storageclass
❗ /Users/mark/Desktop/google-cloud-sdk/bin/kubectl is version 1.16.13-dispatcher, which may have incompatibilites with Kubernetes 1.19.2.
💡 Want kubectl v1.19.2? Try 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" by default
~/Desktop/kubernets took 1m 12s
➜ ./minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
~/Desktop/kubernets took 23s
➜ kubectl cluster-info
Kubernetes master is running at https://127.0.0.1:32772
KubeDNS is running at https://127.0.0.1:32772/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
~/Desktop/kubernets
➜ kubectl run kubia --image=luksa/kubia --port=8080 --generator=run/v1
kubectl run --generator=run/v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
replicationcontroller/kubia created
~/Desktop/kubernets
➜ kubectl run kubia --image=luksa/kubia --port=8080 --generator=run-pod/v1
pod/kubia created
~/Desktop/kubernets
➜ kubectl get pods
NAME READY STATUS RESTARTS AGE
kubia-gnftf 1/1 Running 0 2m44s
~/Desktop/kubernets
➜ kubectl describe pod
Name: kubia-gnftf
Namespace: default
Priority: 0
Node: minikube/192.168.49.2
Start Time: Tue, 27 Oct 2020 10:00:10 +0900
Labels: run=kubia
Annotations: <none>
Status: Running
IP: 172.17.0.5
IPs:
IP: 172.17.0.5
Controlled By: ReplicationController/kubia
Containers:
kubia:
Container ID: docker://8992a63716ba39281423c91ff68527b307bcbb46eaa64d8fe60a3f0611b61f67
Image: luksa/kubia
Image ID: docker-pullable://luksa/kubia@sha256:3f28e304dc0f63dc30f273a4202096f0fa0d08510bd2ee7e1032ce600616de24
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Tue, 27 Oct 2020 10:00:32 +0900
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-6vzh9 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-6vzh9:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-6vzh9
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 Scheduled <unknown> Successfully assigned default/kubia-gnftf to minikube
Normal Pulling 3m38s kubelet, minikube Pulling image "luksa/kubia"
Normal Pulled 3m18s kubelet, minikube Successfully pulled image "luksa/kubia" in 20.3154572s
Normal Created 3m17s kubelet, minikube Created container kubia
Normal Started 3m17s kubelet, minikube Started container kubia
~/Desktop/kubernets
➜ kubectl expose rc kubia --type=LoadBalancer --name kubia-http
service/kubia-http exposed
~/Desktop/kubernets
➜ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23m
kubia-http LoadBalancer 10.107.119.83 <pending> 8080:30466/TCP 46s
~/Desktop/kubernets
➜ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23m
kubia-http LoadBalancer 10.107.119.83 <pending> 8080:30466/TCP 46s
~/Desktop/kubernets
➜ ./minikube service kubia-http
|-----------|------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------|-------------|---------------------------|
| default | kubia-http | 8080 | http://192.168.49.2:30466 |
|-----------|------------|-------------|---------------------------|
🏃 Starting tunnel for service kubia-http.
|-----------|------------|-------------|------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------|-------------|------------------------|
| default | kubia-http | | http://127.0.0.1:56948 |
|-----------|------------|-------------|------------------------|
🎉 Opening service default/kubia-http in default browser...
❗ Because you are using a Docker driver on darwin, the terminal needs to be open to run it.
~/Desktop/kubernets
➜ kubectl get replicationcontrollers
NAME DESIRED CURRENT READY AGE
kubia 1 1 1 10m
~/Desktop/kubernets
➜ kubectl scale rc kubia --replicas=3
replicationcontroller/kubia scaled
~/Desktop/kubernets
➜ kubectl get rc
NAME DESIRED CURRENT READY AGE
kubia 3 3 3 10m
~/Desktop/kubernets
➜ kubectl get pods
NAME READY STATUS RESTARTS AGE
kubia-52tl4 1/1 Running 0 47s
kubia-gnftf 1/1 Running 0 11m
kubia-v886c 1/1 Running 0 47s
~/Desktop/kubernets
➜ curl http://127.0.0.1:57106
You've hit kubia-v886c
~/Desktop/kubernets
➜ curl http://127.0.0.1:57106
You've hit kubia-gnftf
~/Desktop/kubernets
➜ curl http://127.0.0.1:57106
You've hit kubia-52tl4
~/Desktop/kubernets
➜ curl http://127.0.0.1:57106
You've hit kubia-52tl4
~/Desktop/kubernets
➜ curl http://127.0.0.1:57106
You've hit kubia-v886c
~/Desktop/kubernets
➜ curl http://127.0.0.1:57106
You've hit kubia-gnftf
~/Desktop/kubernets
➜ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
kubia-52tl4 1/1 Running 0 3m35s 172.17.0.7 minikube <none> <none>
kubia-gnftf 1/1 Running 0 14m 172.17.0.5 minikube <none> <none>
kubia-v886c 1/1 Running 0 3m35s 172.17.0.6 minikube <none> <none>
~/Desktop/kubernets
➜ kubectl describe pod kubia-52tl4
Name: kubia-52tl4
Namespace: default
Priority: 0
Node: minikube/192.168.49.2
Start Time: Tue, 27 Oct 2020 10:10:51 +0900
Labels: run=kubia
Annotations: <none>
Status: Running
IP: 172.17.0.7
IPs:
IP: 172.17.0.7
Controlled By: ReplicationController/kubia
Containers:
kubia:
Container ID: docker://e65d6b09258674b8abbdb9fa06a0a153312a87863c5e6a8da08a8c54c6dad85e
Image: luksa/kubia
Image ID: docker-pullable://luksa/kubia@sha256:3f28e304dc0f63dc30f273a4202096f0fa0d08510bd2ee7e1032ce600616de24
Port: 8080/TCP
Host Port: 0/TCP
State: Running
Started: Tue, 27 Oct 2020 10:10:57 +0900
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-6vzh9 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
default-token-6vzh9:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-6vzh9
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 Scheduled <unknown> Successfully assigned default/kubia-52tl4 to minikube
Normal Pulling 4m25s kubelet, minikube Pulling image "luksa/kubia"
Normal Pulled 4m20s kubelet, minikube Successfully pulled image "luksa/kubia" in 5.2359442s
Normal Created 4m20s kubelet, minikube Created container kubia
Normal Started 4m20s kubelet, minikube Started container kubia
~/Desktop/kubernets
➜ ./minikube dashboard
🤔 Verifying dashboard health ...
🚀 프록시를 시작하는 중 ...
🤔 Verifying proxy health ...
🎉 Opening http://127.0.0.1:58109/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...