검색

4.4. Knative Serving CLI 명령

download PDF

다음 Knative(kn) CLI 명령을 사용하여 클러스터에서 Knative Serving 작업을 완료할 수 있습니다.

4.4.1. kn service 명령

다음 명령을 사용하여 Knative 서비스를 생성하고 관리할 수 있습니다.

4.4.1.1. Knative CLI를 사용하여 서버리스 애플리케이션 생성

Knative(kn) CLI를 사용하여 서버리스 애플리케이션을 생성하면 YAML 파일을 직접 수정하는 것보다 더 간소화되고 직관적인 사용자 인터페이스를 제공합니다. kn service create 명령을 사용하여 기본 서버리스 애플리케이션을 생성할 수 있습니다.

사전 요구 사항

  • OpenShift Serverless Operator 및 Knative Serving이 클러스터에 설치되어 있습니다.
  • Knative(kn) CLI가 설치되어 있습니다.
  • 프로젝트를 생성했거나 OpenShift Container Platform에서 애플리케이션 및 기타 워크로드를 생성하는 데 적절한 역할 및 권한이 있는 프로젝트에 액세스할 수 있습니다.

절차

  • Knative 서비스를 생성합니다.

    $ kn service create <service-name> --image <image> --tag <tag-value>

    다음과 같습니다.

    • --image 는 애플리케이션의 이미지 URI입니다.
    • --tag 는 서비스로 생성된 초기 버전에 태그를 추가하는 데 사용할 수 있는 선택적 플래그입니다.

      명령 예

      $ kn service create event-display \
          --image quay.io/openshift-knative/knative-eventing-sources-event-display:latest

      출력 예

      Creating service 'event-display' in namespace 'default':
      
        0.271s The Route is still working to reflect the latest desired specification.
        0.580s Configuration "event-display" is waiting for a Revision to become ready.
        3.857s ...
        3.861s Ingress has not yet been reconciled.
        4.270s Ready to serve.
      
      Service 'event-display' created with latest revision 'event-display-bxshg-1' and URL:
      http://event-display-default.apps-crc.testing

4.4.1.2. Knative CLI를 사용하여 서버리스 애플리케이션 업데이트

서비스를 단계적으로 구축할 때 명령줄에서 대화형 세션에 kn service update 명령을 사용할 수 있습니다. kn service apply 명령과 달리 kn service update 명령을 사용하는 경우 Knative 서비스의 전체 구성이 아닌 업데이트하려는 변경 사항만 지정해야 합니다.

명령 예

  • 새 환경 변수를 추가하여 서비스를 업데이트합니다.

    $ kn service update <service_name> --env <key>=<value>
  • 새 포트를 추가하여 서비스를 업데이트합니다.

    $ kn service update <service_name> --port 80
  • 새 요청 및 제한 매개변수를 추가하여 서비스를 업데이트합니다.

    $ kn service update <service_name> --request cpu=500m --limit memory=1024Mi --limit cpu=1000m
  • latest 태그를 개정 버전에 할당합니다.

    $ kn service update <service_name> --tag <revision_name>=latest
  • 서비스의 최신 READY 버전에 대한 태그를 testing에서 staging으로 업데이트합니다.

    $ kn service update <service_name> --untag testing --tag @latest=staging
  • 트래픽의 10%를 수신하는 버전에 test 태그를 추가하고 나머지 트래픽을 서비스의 최신 READY 버전으로 전송합니다.

    $ kn service update <service_name> --tag <revision_name>=test --traffic test=10,@latest=90

4.4.1.3. 서비스 선언 적용

kn service apply 명령을 사용하여 Knative 서비스를 선언적으로 구성할 수 있습니다. 서비스가 존재하지 않으면 기존 서비스가 변경된 옵션으로 업데이트됩니다.

kn service apply 명령은 사용자가 일반적으로 단일 명령으로 서비스 상태를 완전히 지정하여 대상 상태를 선언하려는 셸 스크립트 또는 지속적 통합 파이프라인에 특히 유용합니다.

kn service apply를 사용하는 경우 Knative 서비스에 대한 전체 구성을 제공해야 합니다. 이 동작은 업데이트하려는 옵션을 명령에서 지정하기만 하면 되는 kn service update 명령과 다릅니다.

명령 예

  • 서비스를 생성합니다.

    $ kn service apply <service_name> --image <image>
  • 서비스에 환경 변수를 추가합니다.

    $ kn service apply <service_name> --image <image> --env <key>=<value>
  • JSON 또는 YAML 파일에서 서비스 선언을 읽습니다.

    $ kn service apply <service_name> -f <filename>

4.4.1.4. Knative CLI를 사용하여 서버리스 애플리케이션 설명

kn service describe 명령을 사용하여 Knative 서비스를 설명할 수 있습니다.

명령 예

  • 서비스를 설명합니다.

    $ kn service describe --verbose <service_name>

    --verbose 플래그는 선택 사항이지만 자세한 설명을 제공하기 위해 포함할 수 있습니다. 일반 출력과 자세한 출력의 차이점은 다음 예에 표시됩니다.

    --verbose 플래그를 사용하지 않는 출력 예

    Name:       hello
    Namespace:  default
    Age:        2m
    URL:        http://hello-default.apps.ocp.example.com
    
    Revisions:
      100%  @latest (hello-00001) [1] (2m)
            Image:  docker.io/openshift/hello-openshift (pinned to aaea76)
    
    Conditions:
      OK TYPE                   AGE REASON
      ++ Ready                   1m
      ++ ConfigurationsReady     1m
      ++ RoutesReady             1m

    --verbose 플래그를 사용하는 출력 예

    Name:         hello
    Namespace:    default
    Annotations:  serving.knative.dev/creator=system:admin
                  serving.knative.dev/lastModifier=system:admin
    Age:          3m
    URL:          http://hello-default.apps.ocp.example.com
    Cluster:      http://hello.default.svc.cluster.local
    
    Revisions:
      100%  @latest (hello-00001) [1] (3m)
            Image:  docker.io/openshift/hello-openshift (pinned to aaea76)
            Env:    RESPONSE=Hello Serverless!
    
    Conditions:
      OK TYPE                   AGE REASON
      ++ Ready                   3m
      ++ ConfigurationsReady     3m
      ++ RoutesReady             3m

  • YAML 형식으로 서비스를 설명합니다.

    $ kn service describe <service_name> -o yaml
  • JSON 형식으로 서비스를 설명합니다.

    $ kn service describe <service_name> -o json
  • 서비스 URL만 인쇄합니다.

    $ kn service describe <service_name> -o url
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

© 2024 Red Hat, Inc.