개념 단계 요약

1. 쿠버네티스 클러스터

Kubernetes cluster : 클러스터 생성은 minikube로 보통 생성한다고 보면되고 dashboard 기능이 존재
homebrew로 다운받고 –> Minikube start 실행
2. 애플리케이션 배포하기

$ kubectl get nodes NAME STATUS ROLES AGE VERSION minikube NotReady master 7s v1.17.3 $ kubectl create deployment kubernetes-bootcamp --image=gcr.io/google-samples/kubernetes-bootcamp:v1 deployment.apps/kubernetes-bootcamp created $ kubectl get deployments NAME READY UP-TO-DATE AVAILABLE AGE kubernetes-bootcamp 1/1 1 1 2m5s $
3. 앱 구조 분석


$ kubectl get pod
NAME READY STATUS RESTARTS AGE
kubernetes-bootcamp-765bf4c7b4-v2ffw 1/1 Running 0 2m55s
$ curl http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy/
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-765bf4c7b4-v2ffw | v=1
$ kubectl logs $POD_NAME
Kubernetes Bootcamp App Started At: 2020-07-07T02:52:09.605Z | Running On: kubernetes-bootcamp-765bf4c7b4-v2ffw
Running On: kubernetes-bootcamp-765bf4c7b4-v2ffw | Total Requests: 1 | App Uptime: 52.022 seconds | Log Time: 2020-07-07T02:53:01.627Z
Running On: kubernetes-bootcamp-765bf4c7b4-v2ffw | Total Requests: 2 | App Uptime: 170.553 seconds | Log Time: 2020-07-07T02:55:00.158Z
$ echo $POD_NAME
kubernetes-bootcamp-765bf4c7b4-v2ffw
$ kubectl exec $POD_NAME envPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=kubernetes-bootcamp-765bf4c7b4-v2ffw
KUBERNETES_SERVICE_HOST=10.96.0.1
KUBERNETES_SERVICE_PORT=443KUBERNETES_SERVICE_PORT_HTTPS=443
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
NPM_CONFIG_LOGLEVEL=info
NODE_VERSION=6.3.1
HOME=/root
$ kubectl exec -ti $POD_NAME bash
root@kubernetes-bootcamp-765bf4c7b4-v2ffw:/# ls -ltr
total 452
drwxr-xr-x 2 root root 4096 May 30 2016 home
drwxr-xr-x 2 root root 4096 May 30 2016 boot
drwxr-xr-x 2 root root 4096 Jun 8 2016 srv
drwxr-xr-x 2 root root 4096 Jun 8 2016 opt
drwxr-xr-x 2 root root 4096 Jun 8 2016 mnt
drwxr-xr-x 2 root root 4096 Jun 8 2016 media
drwxr-xr-x 2 root root 4096 Jun 8 2016 lib64
drwxr-xr-x 2 root root 4096 Jun 8 2016 bin
drwxr-xr-x 2 root root 4096 Jun 8 2016 sbin
drwxr-xr-x 9 root root 4096 Jun 9 2016 lib
-rw------- 5 root root 393216 Jun 9 2016 core
drwxrwxrwt 2 root root 4096 Jul 22 2016 tmp
drwxr-xr-x 11 root root 4096 Jul 22 2016 var
drwxr-xr-x 10 root root 4096 Jul 22 2016 usr
drwx------ 3 root root 4096 Jul 22 2016 root
-rw-r--r-- 1 root root 742 Jul 29 2016 server.js
dr-xr-xr-x 13 root root 0 Jul 7 02:52 sys
drwxr-xr-x 1 root root 4096 Jul 7 02:52 etc
dr-xr-xr-x 212 root root 0 Jul 7 02:52 proc
drwxr-xr-x 1 root root 4096 Jul 7 02:52 run
drwxr-xr-x 5 root root 360 Jul 7 02:52 dev
root@kubernetes-bootcamp-765bf4c7b4-v2ffw:/# cat server.js
var http = require('http');
var requests=0;
var podname= process.env.HOSTNAME;
var startTime;
var host;
var handleRequest = function(request, response) {
response.setHeader('Content-Type', 'text/plain');
response.writeHead(200);
response.write("Hello Kubernetes bootcamp! | Running on: ");
response.write(host);
response.end(" | v=1\n");
console.log("Running On:" ,host, "| Total Requests:", ++requests,"| App Uptime:", (new Date() - startTime)/1000 , "seconds", "| Log Time:",new Date());
}
var www = http.createServer(handleRequest);
www.listen(8080,function () {
startTime = new Date();;
host = process.env.HOSTNAME;
console.log ("Kubernetes Bootcamp App Started At:",startTime, "| RunningOn: " ,host, "\n" );
});
root@kubernetes-bootcamp-765bf4c7b4-v2ffw:/# curl localhost:8080
Hello Kubernetes bootcamp! | Running on: kubernetes-bootcamp-765bf4c7b4-v2ffw | v=1
root@kubernetes-bootcamp-765bf4c7b4-v2ffw:/# exit
exit
자료출처 : https://kubernetes.io/ko/docs/tutorials/kubernetes-basics/