클라우드/OpenShift

[OpenShift] S2I(Source to Image)로 어플리케이션 생성

세브웁스 2023. 6. 7. 16:49
반응형
실습 환경 : Redhat WorkStation

 

S2I(Source to Image)로 어플리케이션 생성

 

S2I 정의

- 어플리케이션 소스 코드로 컨테이너 이미지 빌드 툴

- Git 레포지토리에서 어플리케이션의 소스 코드를 가져와 원하는 언어 및 프레임워크를 기반으로 기본 컨테이너에 소스 코드 삽입하고 조합된 어플리케이션을 실행하는 새 컨테이너 이미지 생성

 

장점

- 사용자 효율성 : 표준 프로그래밍 언어 툴을 사용하여 작업

- 패칭 : 보안 문제로 인해 기본 이미지에 패치가 필요한 경우 S2I를 사용하면 어플리케이션 다시 빌드 가능

- 속도 :각 단계에서 새 계층을 생성하지 않고 조합 프로세스를 통해 다수의 복합 작업을 수행

- 에코시스템 : S2I는 기본 이미지 및 스크립트를 여러 유형의 어플리케이션에 맞게 수정 가능, 재사용할 수 있는 이미지의 공유

 

이미지 스트림 설명

- 준비물 : 어플리케이션 소스,기본 이미지(S2I 빌더 이미지)

- 두 요소 중 하나가 업데이트되면 OpenShift에서 새 컨테이너 이미지 생성

- 명령에 이미지 스트림 미지정시 레포지토리의 루트에 있는 특정 파일을 기반으로 사용할 언어 빌더 판별

- 탐지된 언어에 대해 지원하는 이미지 스트림 태그나 탐지된 언어의 이름과 일치하는 이미지 스트림을 검색


실습

해당 작업 전 실습환경 구축

https://shyen.tistory.com/92

 

[OpenShift] 실습 환경 구축

0. 실습 환경 구축 0.1. 실습 환경 구축 [student@workstation ~]$ lab-configure · Enter the GitHub account name: yourgituser 1 Verifying GitHub account name: yourgituser · Enter the Quay.io account name: yourquayuser 2 Verifying Quay.io account

shyen.tistory.com


 

1. 새 분기를 만들며 내보내기

1.1 랩 파일 다운로드

[student@workstation ~]$ lab openshift-s2i start

 1.2 깃 레포지토리의 로컬 복제본 입력, 교육 과정 레포지토리의 master 분기 체크아웃

[student@workstation ~]$ cd ~/DO180-apps
[student@workstation DO180-apps]$ git checkout master

 1.3 변경 내용 저장용 새 분기 생성

[student@workstation DO180-apps]$ git checkout -b s2i
[student@workstation DO180-apps]$ git push -u origin s2i

2. 랩 환경 준비

2.1. 환경 변수 로드

[student@workstation DO180-apps]$ source /usr/local/etc/ocp4.config

 2.2.OpenShift 클러스터에 로그인

[student@workstation DO180-apps]$ oc login -u ${RHT_OCP4_DEV_USER} \
>  -p ${RHT_OCP4_DEV_PASSWORD} ${RHT_OCP4_MASTER_API}

 

2.3. 연습에서 생성되는 리소스에 대한 RHOCP 개발자 사용자 이름을 포함하는 프로젝트 생성

[student@workstation DO180-apps]$ oc new-project ${RHT_OCP4_DEV_USER}-s2i

 

3. PHP 어플리케이션 생성

3.1. oc-new-app 명령을 사용하여 PHP 어플리케이션 생성

[student@workstation DO180-apps]$ oc new-app php:7.3 --name=php-helloworld \
> https://github.com/${RHT_OCP4_GITHUB_USER}/DO180-apps#s2i \
> --context-dir php-helloworld

3.2. 빌드 프로세스 시작 확인

[student@workstation openshift-s2i]$ oc get pods

 

3.3. 빌드에 대한 로그 검사

[student@workstation DO180-apps]$ oc logs --all-containers \
> -f php-helloworld-1-build

 

3.4. 이 어플리케이션의 디플로이먼트 검토

[student@workstation DO180-apps]$ oc describe deployment/php-helloworld

 

3.5. 어플리케이션 테스트 경로 추가

[student@workstation DO180-apps]$ oc expose service php-helloworld \
> --name ${RHT_OCP4_DEV_USER}-helloworld

3.6. 새 경로와 연결된 URL 찾기

[student@workstation DO180-apps]$ oc get route -o jsonpath='{..spec.host}{"\n"}'

 

3.7. URL get 요청을 통해 어플리케이션 테스트

[student@workstation DO180-apps]$ curl -s \
> ${RHT_OCP4_DEV_USER}-helloworld-${RHT_OCP4_DEV_USER}-s2i.\
> ${RHT_OCP4_WILDCARD_DOMAIN}

 

4. S2I 빌드를 시작하도록 명령 실행 후 어플리케이션 빌드

4.1. 소스 디코드 디렉토리 입력

[student@workstation DO180-apps]$ cd ~/DO180-apps/php-helloworld

4.2. index.php 편집

<?php
print "Hello, World! php version is " . PHP_VERSION . "\n";
print "A change is a coming!\n";
?>

 

4.3. 변경 사항을 커밋하고 코드를 다시 원격 Git 레포지토리에 내보내기

[student@workstation php-helloworld]$ git add .
[student@workstation php-helloworld]$ git commit -m 'Changed index page contents.'
[student@workstation php-helloworld]$ git push origin s2i

.

4.4. S2I 빌드 프로세스를 시작하고 빌드 및 배포 완료 확인

[student@workstation php-helloworld]$ oc start-build php-helloworld
[student@workstation php-helloworld]$ oc get pods
[student@workstation php-helloworld]$ oc logs php-helloworld-2-build -f

.

4.5. 두 번째 빌드가 완료된 후 어플리케이션 상태 확인

[student@workstation php-helloworld]$ oc get pods

.

4.6. 어플리케이션에서 변경정보 확인

[student@workstation php-helloworld]$ curl -s \
> ${RHT_OCP4_DEV_USER}-helloworld-${RHT_OCP4_DEV_USER}-s2i.\
> ${RHT_OCP4_WILDCARD_DOMAIN}

.

실습 종료

[student@workstation php-helloworld]$ lab openshift-s2i finish

반응형