Kantive Serving 구성요소 설치
# 구성요소 설치
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.2.0/serving-crds.yaml
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.2.0/serving-core.yaml
네트워크 계층 설치
# Kourier 설치
kubectl apply -f https://github.com/knative/net-kourier/releases/download/knative-v1.2.0/kourier.yaml
kubectl patch configmap/config-network \
--namespace knative-serving \
--type merge \
--patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}'
kubectl --namespace kourier-system get service kourier
Istio가 더 유명한 것 같은데 안내서에서 Kourier를 권장하길래 이걸로 설치했어요.
DNS 구성
# magic DNS (sslip.io)
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.2.0/serving-default-domain.yaml
http://helloworld-nodejs.default.1.2.3.4.sslip.io
위 주소와 같은 DNS를 열어주는 역할 같은데 자세히는 잘 모르겠네요.
테스트 배포
공식예제의 hello-world 서버를 배포해보겠습니다.
code
서버
const express = require('express');
const app = express();
app.get('/', (req, res) => {
console.log('Hello world received a request.');
const target = process.env.TARGET || 'World';
res.send(`Hello ${target}!\n`);
});
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log('Hello world listening on port', port);
});
도커
# Use the official lightweight Node.js 12 image.
# https://hub.docker.com/_/node
FROM node:12-slim
# Create and change to the app directory.
WORKDIR /usr/src/app
# Copy application dependency manifests to the container image.
# A wildcard is used to ensure both package.json AND package-lock.json are copied.
# Copying this separately prevents re-running npm install on every code change.
COPY package*.json ./
# Install production dependencies.
RUN npm install --only=production
# Copy local code to the container image.
COPY . ./
# Run the web service on container startup.
CMD [ "npm", "start" ]
쿠버네티스 yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-nodejs
namespace: default
spec:
template:
spec:
containers:
- image: docker.io/younhu6/hello-world-node
env:
- name: TARGET
value: "Node.js Sample v1"
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: helloworld-nodejs
namespace: default
spec:
template:
spec:
containers:
- image: docker.io/younhu6/hello:0.4
env:
- name: TARGET
value: "Node.js Sample v1"
hello-world 를 출력하는 서버의 이미지를 도커에 업로드했습니다. (younhu6/hello-world-node)
kubectl apply -f service.yaml
위 명령어로 쿠버네티스에 서비스를 생성합니다.
서비스가 생성되면 knative는 다음 단계를 수행합니다.
- 앱에 대한 변경 불가능한 버전을 만든다.
- 앱에 대한 경로, 수신, 서비스 및 부하 분산을 생성하기 위한 네트워크 프로그래밍.
- 파드를 자동으로 확장 및 축소한다.
kubectl get ksvc
명령어로 생성된 서비스를 확인합니다.![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ff41e1985-7529-47a1-8546-dc65b7763081%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2022-03-13_%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE_7.54.36.png?table=block&id=d674a9ab-15a5-44ed-bc83-cb501ea4681a&cache=v2)
배포 확인
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F504e059a-c728-4aa0-9c88-0f0380744844%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2022-03-13_%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE_11.23.33.png?table=block&id=36768624-bb54-4828-a793-e3b6fedfd6d4&cache=v2)
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2Ff659e91c-a939-494a-8f08-4d76745051ac%2F%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA_2022-03-13_%E1%84%8B%E1%85%A9%E1%84%92%E1%85%AE_11.44.31.png?table=block&id=b0dc8a42-8443-4f25-8310-48024908e691&cache=v2)
vultr의 도쿄리전인데 응답시간이 100ms 아래로도 나오네요
Loading Comments...