Getting-Started Kubernetes!

Getting started Kubernetes


1. Linux


Getting started Hello World on Linux.

CentOS에 nodejs 설치 :

yum install epel-release
yum -y install nodejs

1-1) hello.js

var http = require('http');
var content = function(req, resp) {
 resp.end("Hello Kubernetes!" + "\n");
 resp.writeHead(200);
}
var w = http.createServer(content);
w.listen(8000);
node hello.js


2. Docker


Getting started Hello World on Linux.

2-1) Dockerfile

FROM node:slim
EXPOSE 8000
COPY hello.js .
CMD node hello.js

2-2) Docker Hub Site

https://hub.docker.com/

2-3) Docker Container Run

docker build -t kubetm/hello .
-t : 레파지토리/이미지명:버전

docker images
docker run -d -p 8100:8000 kubetm/hello
-d : 백그라운드 모드
-p : 포트변경

docker ps
docker exec -it c403442e8a59 /bin/bash

2-4) Docker Image Push

docker login
docker push kubetm/hello


3. Kubernetes


Getting started Hello World on Kubernetes.

3-1) Pod

apiVersion: v1
kind: Pod
metadata:
  name: hello-pod
  labels:
    app: hello
spec:
  containers:
  - name: hello-container
    image: kubetm/hello
    ports:
    - containerPort: 8000

3-2) Service


apiVersion: v1
kind: Service
metadata:
  name: hello-svc
spec:
  selector:
    app: hello
  ports:
    - port: 8200
      targetPort: 8000
  externalIPs:
  - 192.168.56.30

apiVersion: v1
kind: Service
metadata:
  name: hello-svc
spec:
  selector:
    app: hello
  ports:
    - port: 8200
      targetPort: 8000
  externalIPs:
  - 192.168.0.30