Apache Kafka용 Google Cloud 관리형 서비스 클러스터 삭제

클러스터를 삭제하려면 Google Cloud 콘솔, Google Cloud CLI, 클라이언트 라이브러리 또는 관리형 Kafka API를 사용하면 됩니다. 오픈소스 Apache Kafka API를 사용하여 클러스터를 삭제할 수는 없습니다.

클러스터를 삭제하는 데 필요한 역할 및 권한

클러스터를 삭제하는 데 필요한 권한을 얻으려면 관리자에게 프로젝트의 관리형 Kafka 클러스터 편집자 (roles/managedkafka.clusterEditor) IAM 역할을 부여해 달라고 요청하세요. 역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

이 사전 정의된 역할에는 클러스터를 삭제하는 데 필요한 권한이 포함되어 있습니다. 필요한 정확한 권한을 보려면 필수 권한 섹션을 펼치세요.

필수 권한

클러스터를 삭제하려면 다음 권한이 필요합니다.

  • 클러스터에 대한 클러스터 삭제 권한: managedkafka.clusters.delete
  • 클러스터가 포함된 위치에 대한 모든 클러스터 나열 권한 이 권한은 다음을 사용하여 클러스터를 삭제할 때만 필요합니다. Google Cloud: managedkafka.clusters.list

커스텀 역할이나 다른 사전 정의된 역할을 사용하여 이 권한을 부여받을 수도 있습니다.

관리형 Kafka 클러스터 편집자 역할을 사용하면 Apache Kafka용 관리형 서비스 클러스터에서 주제 및 소비자 그룹을 만들거나 삭제하거나 수정할 수 없습니다. 또한 클러스터 내에서 메시지를 게시하거나 소비하기 위한 데이터 영역 액세스도 허용하지 않습니다. 이 역할에 대한 자세한 내용은 Apache Kafka용 관리형 서비스 사전 정의된 역할을 참고하세요.

클러스터 삭제

다음은 클러스터를 삭제하기 전에 고려해야 할 중요한 사항 목록입니다.

  • 데이터 손실: 클러스터를 삭제하면 클러스터 내에 저장된 모든 데이터가 지워집니다. 주제, 메시지, 구성, 기타 연결된 리소스를 비롯하여 이 작업은 되돌릴 수 없습니다.

  • 서비스 중단: 클러스터에 의존하는 애플리케이션 또는 서비스는 액세스 권한을 잃고 중단을 경험합니다. 클러스터를 삭제하기 전에 이 종속성을 처리할 계획이 있는지 확인하세요.

  • 결제: 클러스터가 삭제된 후에는 클러스터에 대한 요금이 청구되지 않습니다. 하지만 삭제 시점까지 사용된 리소스에 대해서는 요금이 청구될 수 있습니다.

  • 비동기 작업: 기본적으로 삭제 명령어는 비동기식으로 작동합니다. 즉시 반환되며 삭제 진행 상황을 별도로 추적할 수 있습니다.

클러스터를 삭제하려면 다음 단계를 따르세요.

콘솔

  1. Google Cloud 콘솔에서 클러스터 페이지로 이동합니다.

    클러스터로 이동

  2. 클러스터 목록에서 삭제할 클러스터를 선택합니다.

  3. 삭제 를 클릭합니다.

gcloud

  1. 콘솔에서 Cloud Shell을 활성화합니다. Google Cloud

    Cloud Shell 활성화

    콘솔 하단에 Cloud Shell 세션이 시작되고 명령줄 프롬프트가 표시됩니다. Google Cloud Cloud Shell은 Google Cloud CLI가 사전 설치된 셸 환경으로, 현재 프로젝트의 값이 이미 설정되어 있습니다. 세션이 초기화되는 데 몇 초 정도 걸릴 수 있습니다.

  2. gcloud managed-kafka clusters delete 명령어를 실행합니다.

    gcloud managed-kafka clusters delete CLUSTER_ID \
        --location=LOCATION
    

    다음을 바꿉니다.

    • CLUSTER_ID: 클러스터의 ID 또는 이름입니다.
    • LOCATION: 클러스터의 위치입니다.

REST

요청 데이터를 사용하기 전에 다음을 바꿉니다.

  • PROJECT_ID: 프로젝트 ID Google Cloud
  • LOCATION: 클러스터의 위치
  • CLUSTER_ID: 클러스터의 ID

HTTP 메서드 및 URL:

DELETE https://managedkafka.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/clusters/CLUSTER_ID

요청을 보내려면 다음 옵션 중 하나를 펼칩니다.

다음과 비슷한 JSON 응답이 표시됩니다.

{
  "name": "projects/PROJECT_ID/locations/LOCATION/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.managedkafka.v1.OperationMetadata",
    "createTime": "CREATE_TIME",
    "target": "projects/PROJECT_ID/locations/LOCATION/clusters/CLUSTER_ID",
    "verb": "delete",
    "requestedCancellation": false,
    "apiVersion": "v1"
  },
  "done": false
}

Go

이 샘플을 사용해 보기 전에 클라이언트 라이브러리 설치의 Go 설정 안내를 따르세요. 자세한 내용은 Apache Kafka용 관리형 서비스 Go API 참조 문서를 참고하세요.

Apache Kafka용 관리형 서비스에 인증하려면 애플리케이션 기본 사용자 인증 정보(ADC)를 설정하세요. 자세한 내용은 로컬 개발 환경의 ADC 설정을 참조하세요.

import (
	"context"
	"fmt"
	"io"

	"cloud.google.com/go/managedkafka/apiv1/managedkafkapb"
	"google.golang.org/api/option"

	managedkafka "cloud.google.com/go/managedkafka/apiv1"
)

func deleteCluster(w io.Writer, projectID, region, clusterID string, opts ...option.ClientOption) error {
	// projectID := "my-project-id"
	// region := "us-central1"
	// clusterID := "my-cluster"
	ctx := context.Background()
	client, err := managedkafka.NewClient(ctx, opts...)
	if err != nil {
		return fmt.Errorf("managedkafka.NewClient got err: %w", err)
	}
	defer client.Close()

	clusterPath := fmt.Sprintf("projects/%s/locations/%s/clusters/%s", projectID, region, clusterID)
	req := &managedkafkapb.DeleteClusterRequest{
		Name: clusterPath,
	}
	op, err := client.DeleteCluster(ctx, req)
	if err != nil {
		return fmt.Errorf("client.DeleteCluster got err: %w", err)
	}
	err = op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("op.Wait got err: %w", err)
	}
	fmt.Fprint(w, "Deleted cluster\n")
	return nil
}

자바

이 샘플을 사용해 보기 전에 클라이언트 라이브러리 설치의 자바 설정 안내를 따르세요. 자세한 내용은 Apache Kafka용 관리형 서비스 자바 API 참조 문서를 참고하세요.

Apache Kafka용 관리형 서비스에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정하세요. 자세한 내용은 로컬 개발 환경의 ADC 설정을 참고하세요.


import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.longrunning.OperationSnapshot;
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.retrying.TimedRetryAlgorithm;
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.managedkafka.v1.ClusterName;
import com.google.cloud.managedkafka.v1.DeleteClusterRequest;
import com.google.cloud.managedkafka.v1.ManagedKafkaClient;
import com.google.cloud.managedkafka.v1.ManagedKafkaSettings;
import com.google.cloud.managedkafka.v1.OperationMetadata;
import com.google.protobuf.Empty;
import java.io.IOException;
import java.time.Duration;

public class DeleteCluster {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the example.
    String projectId = "my-project-id";
    String region = "my-region"; // e.g. us-east1
    String clusterId = "my-cluster";
    deleteCluster(projectId, region, clusterId);
  }

  public static void deleteCluster(String projectId, String region, String clusterId)
      throws Exception {

    // Create the settings to configure the timeout for polling operations
    ManagedKafkaSettings.Builder settingsBuilder = ManagedKafkaSettings.newBuilder();
    TimedRetryAlgorithm timedRetryAlgorithm = OperationTimedPollAlgorithm.create(
        RetrySettings.newBuilder()
            .setTotalTimeoutDuration(Duration.ofHours(1L))
            .build());
    settingsBuilder.deleteClusterOperationSettings()
        .setPollingAlgorithm(timedRetryAlgorithm);

    try (ManagedKafkaClient managedKafkaClient = ManagedKafkaClient.create(
        settingsBuilder.build())) {
      DeleteClusterRequest request =
          DeleteClusterRequest.newBuilder()
              .setName(ClusterName.of(projectId, region, clusterId).toString())
              .build();
      OperationFuture<Empty, OperationMetadata> future =
          managedKafkaClient.deleteClusterOperationCallable().futureCall(request);

      // Get the initial LRO and print details. CreateCluster contains sample code for polling logs.
      OperationSnapshot operation = future.getInitialFuture().get();
      System.out.printf("Cluster deletion started. Operation name: %s\nDone: %s\nMetadata: %s\n",
          operation.getName(),
          operation.isDone(),
          future.getMetadata().get().toString());

      future.get();
      System.out.println("Deleted cluster");
    } catch (IOException | ApiException e) {
      System.err.printf("managedKafkaClient.deleteCluster got err: %s", e.getMessage());
    }
  }
}

Python

이 샘플을 사용해 보기 전에 클라이언트 라이브러리 설치의 Python 설정 안내를 따르세요. 자세한 내용은 Apache Kafka용 관리형 서비스 Python API 참조 문서를 참고하세요.

Apache Kafka용 관리형 서비스에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정하세요. 자세한 내용은 로컬 개발 환경의 ADC 설정을 참조하세요.

from google.api_core.exceptions import GoogleAPICallError
from google.cloud import managedkafka_v1

# TODO(developer)
# project_id = "my-project-id"
# region = "us-central1"
# cluster_id = "my-cluster"

client = managedkafka_v1.ManagedKafkaClient()

request = managedkafka_v1.DeleteClusterRequest(
    name=client.cluster_path(project_id, region, cluster_id),
)

try:
    operation = client.delete_cluster(request=request)
    print(f"Waiting for operation {operation.operation.name} to complete...")
    operation.result()
    print("Deleted cluster")
except GoogleAPICallError as e:
    print(f"The operation failed with error: {e.message}")

다음 단계

Apache Kafka®는 미국 및/또는 다른 국가에서 사용되는 Apache Software Foundation 또는 해당 계열사의 등록 상표입니다.