배포 만들기

이 페이지에서는 Game Servers 배포를 생성, 나열, 설명하는 방법에 대해 다룹니다. 배포는 일부 또는 모든 렐름에 배포할 수 있는 하나 이상의 소프트웨어 버전을 관리합니다.

시작하기 전에

시작하기 전에 Game Servers 개요의 주요 개념을 숙지하는 것이 좋습니다. 또한 다음 태스크를 수행했는지 확인합니다.

  • Game Services API가 사용 설정되어 있는지 확인합니다.
  • Game Services API 사용 설정
  • Cloud SDK가 설치된 셸을 선택하거나 API 클라이언트를 사용하세요.
  • Cloud Shell

    Cloud Shell을 시작하려면 다음 단계를 수행하세요.

    1. Google Cloud Console로 이동합니다.

      Google Cloud Console

    2. Console의 오른쪽 상단에서 Cloud Shell 활성화 버튼을 클릭합니다.

    Console 하단의 프레임에서 Cloud Shell 세션이 열립니다. 이 셸을 사용하여 gcloud 명령어를 실행합니다.

    로컬 셸

    gcloud를 설치하려면 gcloud 명령줄 도구가 포함된 Cloud SDK를 설치합니다.

    gcloud 명령줄 도구에 대해 원하는 기본 프로젝트를 설정했는지 확인합니다. 그렇지 않으면 나중에 각 명령어에 대해 명시적으로 --project 플래그를 지정해야 합니다.

    gcloud config list project
    

    사용할 수 없는 경우 다음 명령어를 실행하여 기본 프로젝트를 설정하고 project-id를 원하는 프로젝트 ID로 바꾸세요.

    gcloud config set project project-id
    

    다음 명령어를 실행하여 Google Cloud SDK의 버전을 확인합니다. Game Servers에는 306.0.0 이상의 SDK 버전이 필요합니다.

    gcloud version
    

    설치를 업데이트하려면 다음 명령어를 실행합니다.

    gcloud components update
    

    클라이언트 라이브러리

    클라이언트 라이브러리를 사용하여 Google Cloud Game Servers를 프로그래매틱 방식으로 제어할 수 있습니다. 라이브러리 사용 및 인증에 대한 안내는 클라이언트 라이브러리 개요를 참조하세요.

배포 만들기

gcloud

gcloud 명령줄 도구를 사용하여 배포를 만들 수 있습니다.

배포를 만들려면 다음 명령어를 실행하고 deploymentID를 적절한 값으로 바꿉니다.

gcloud game servers deployments create deploymentID

Go

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.


import (
	"context"
	"fmt"
	"io"

	gaming "cloud.google.com/go/gaming/apiv1"
	gamingpb "google.golang.org/genproto/googleapis/cloud/gaming/v1"
)

// createGameServerDeployment creates a game server deployment.
func createGameServerDeployment(w io.Writer, projectID, deploymentID string) error {
	// projectID := "my-project"
	// deploymentID := "mydeployment"
	ctx := context.Background()
	client, err := gaming.NewGameServerDeploymentsClient(ctx)
	if err != nil {
		return fmt.Errorf("NewGameServerDeploymentsClient: %v", err)
	}
	defer client.Close()

	// Location is hard coded as global, as Game Server Deployments can only be
	// created in global.  This is done for all operations on Game Server
	// Deployments, as well as for its child resource types.
	req := &gamingpb.CreateGameServerDeploymentRequest{
		Parent:       fmt.Sprintf("projects/%s/locations/global", projectID),
		DeploymentId: deploymentID,
		GameServerDeployment: &gamingpb.GameServerDeployment{
			Description: "My Game Server Deployment",
		},
	}

	op, err := client.CreateGameServerDeployment(ctx, req)
	if err != nil {
		return fmt.Errorf("CreateGameServerDeployment: %v", err)
	}
	resp, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("Wait: %v", err)
	}

	fmt.Fprintf(w, "Deployment created: %v", resp.Name)
	return nil
}

자바

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.


import com.google.api.gax.longrunning.OperationFuture;
import com.google.cloud.gaming.v1.CreateGameServerDeploymentRequest;
import com.google.cloud.gaming.v1.GameServerDeployment;
import com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient;
import com.google.cloud.gaming.v1.OperationMetadata;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateDeployment {
  public static void createGameServerDeployment(String projectId, String deploymentId)
      throws IOException, InterruptedException, ExecutionException, TimeoutException {
    // String projectId = "your-project-id";
    // String deploymentId = "your-game-server-deployment-id";
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.create()) {

      // Build a spec as shown at https://agones.dev/site/docs/reference/gameserver/
      JsonObject container = new JsonObject();
      container.addProperty("name", "default");
      container.addProperty("image", "gcr.io/agones-images/default:1.0");

      JsonArray containers = new JsonArray();
      containers.add(container);

      JsonObject spec = new JsonObject();
      spec.add("containers", containers);

      JsonObject template = new JsonObject();
      template.add("spec", spec);

      JsonObject port = new JsonObject();
      port.addProperty("name", "default");

      JsonArray ports = new JsonArray();
      ports.add(port);

      JsonObject specObject = new JsonObject();
      specObject.add("ports", ports);
      specObject.add("template", template);

      String parent = String.format("projects/%s/locations/global", projectId);
      String deploymentName = String.format("%s/gameServerDeployments/%s", parent, deploymentId);

      GameServerDeployment gameServerDeployment =
          GameServerDeployment.newBuilder().setName(deploymentName).build();

      CreateGameServerDeploymentRequest request =
          CreateGameServerDeploymentRequest.newBuilder()
              .setParent(parent)
              .setDeploymentId(deploymentId)
              .setGameServerDeployment(gameServerDeployment)
              .build();

      OperationFuture<GameServerDeployment, OperationMetadata> call =
          client.createGameServerDeploymentAsync(request);

      GameServerDeployment created = call.get(1, TimeUnit.MINUTES);
      System.out.println("Game Server Deployment created: " + created.getName());
    }
  }
}

Node.js

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.

const {
  GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function createGameServerDeployment() {
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const projectId = 'Your Google Cloud Project ID';
  // const deploymentId = 'A unique ID for the Game Server Deployment';
  const request = {
    parent: `projects/${projectId}/locations/global`,
    deploymentId: deploymentId,
    gameServerDeployment: {
      description: 'nodejs test deployment',
    },
  };

  const [operation] = await client.createGameServerDeployment(request);
  const [result] = await operation.promise();

  console.log('Game Server Deployment created:');
  console.log(`\t Deployment name: ${result.name}`);
  console.log(`\t Deployment description: ${result.description}`);
}

createGameServerDeployment();

Python

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.

def create_deployment(project_id, deployment_id):
    """Creates a game server deployment."""

    client = gaming.GameServerDeploymentsServiceClient()

    # Location is hard coded as global, as game server deployments can
    # only be created in global.  This is done for all operations on
    # game server deployments, as well as for its child resource types.
    request = game_server_deployments.CreateGameServerDeploymentRequest(
        parent=f"projects/{project_id}/locations/global",
        deployment_id=deployment_id,
        game_server_deployment=game_server_deployments.GameServerDeployment(
            description="My Game Server Deployment"
        ),
    )

    operation = client.create_game_server_deployment(request)
    print(f"Create deployment operation: {operation.operation.name}")
    operation.result(timeout=120)

배포 나열

gcloud

gcloud 명령줄 도구를 사용하여 배포를 나열할 수 있습니다.

배포를 나열하려면 다음 명령어를 실행합니다.

gcloud game servers deployments list

Go

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.


import (
	"context"
	"fmt"
	"io"

	gaming "cloud.google.com/go/gaming/apiv1"
	"google.golang.org/api/iterator"
	gamingpb "google.golang.org/genproto/googleapis/cloud/gaming/v1"
)

// listGameServerDeployments lists the game server deployments.
func listGameServerDeployments(w io.Writer, projectID string) error {
	// projectID := "my-project"
	// realmID := "myrealm"
	ctx := context.Background()
	client, err := gaming.NewGameServerDeploymentsClient(ctx)
	if err != nil {
		return fmt.Errorf("NewGameServerDeploymentsClient: %v", err)
	}
	defer client.Close()

	req := &gamingpb.ListGameServerDeploymentsRequest{
		Parent: fmt.Sprintf("projects/%s/locations/global", projectID),
	}

	it := client.ListGameServerDeployments(ctx, req)
	for {
		resp, err := it.Next()
		if err == iterator.Done {
			break
		}
		if err != nil {
			return fmt.Errorf("Next: %v", err)
		}

		fmt.Fprintf(w, "Deployment listed: %v\n", resp.Name)
	}

	return nil
}

자바

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.


import com.google.cloud.gaming.v1.GameServerDeployment;
import com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient;
import com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient.ListGameServerDeploymentsPagedResponse;
import com.google.cloud.gaming.v1.ListGameServerDeploymentsRequest;
import com.google.common.base.Strings;
import java.io.IOException;

public class ListDeployments {
  public static void listGameServerDeployments(String projectId) throws IOException {
    // String projectId = "your-project-id";
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.create()) {
      String parent = String.format("projects/%s/locations/global", projectId);

      ListGameServerDeploymentsPagedResponse response = client.listGameServerDeployments(parent);
      for (GameServerDeployment deployment : response.iterateAll()) {
        System.out.println("Game Server Deployment found: " + deployment.getName());
      }

      while (!Strings.isNullOrEmpty(response.getNextPageToken())) {
        ListGameServerDeploymentsRequest request =
            ListGameServerDeploymentsRequest.newBuilder()
                .setParent(parent)
                .setPageToken(response.getNextPageToken())
                .build();
        response = client.listGameServerDeployments(request);
        for (GameServerDeployment deployment : response.iterateAll()) {
          System.out.println("Game Server Deployment found: " + deployment.getName());
        }
      }
    }
  }
}

Node.js

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.

const {
  GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function listGameServerDeployments() {
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const projectId = 'Your Google Cloud Project ID';
  const request = {
    parent: `projects/${projectId}/locations/global`,
  };

  const [results] = await client.listGameServerDeployments(request);
  for (const deployment of results) {
    console.log(`Deployment name: ${deployment.name}`);
    console.log(`Deployment description: ${deployment.description}`);

    const createTime = deployment.createTime;
    const createDate = new Date(createTime.seconds * 1000);
    console.log(
      `Deployment created on: ${createDate.toLocaleDateString()}\n`
    );
  }
}

listGameServerDeployments();

Python

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.

def list_deployments(project_id):
    """Lists the existing game server deployments."""

    client = gaming.GameServerDeploymentsServiceClient()

    # Location is hard coded as global, as game server deployments can
    # only be created in global.  This is done for all operations on
    # game server deployments, as well as for its child resource types.
    response = client.list_game_server_deployments(
        parent=f"projects/{project_id}/locations/global"
    )

    for deployment in response.game_server_deployments:
        print(f"Name: {deployment.name}")

    return response.game_server_deployments

배포 설명

gcloud

gcloud 명령줄 도구를 사용하여 생성 시간 또는 업데이트 시간과 같은 배포에 대한 세부정보를 가져올 수 있습니다.

배포를 설명하려면 다음 명령어를 실행하고 deploymentID를 이전에 만든 배포의 식별자로 바꿉니다.

gcloud game servers deployments describe deploymentID

Go

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.


import (
	"context"
	"fmt"
	"io"

	gaming "cloud.google.com/go/gaming/apiv1"
	gamingpb "google.golang.org/genproto/googleapis/cloud/gaming/v1"
)

// getGameServerDeployment retrieves info on a game server deployment.
func getGameServerDeployment(w io.Writer, projectID, deploymentID string) error {
	// projectID := "my-project"
	// deploymentID := "mydeployment"
	ctx := context.Background()
	client, err := gaming.NewGameServerDeploymentsClient(ctx)
	if err != nil {
		return fmt.Errorf("NewGameServerDeploymentsClient: %v", err)
	}
	defer client.Close()

	req := &gamingpb.GetGameServerDeploymentRequest{
		Name: fmt.Sprintf("projects/%s/locations/global/gameServerDeployments/%s", projectID, deploymentID),
	}

	resp, err := client.GetGameServerDeployment(ctx, req)
	if err != nil {
		return fmt.Errorf("GetGameServerDeployment: %v", err)
	}

	fmt.Fprintf(w, "Deployment retrieved: %v", resp.Name)
	return nil
}

자바

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.


import com.google.cloud.gaming.v1.GameServerDeployment;
import com.google.cloud.gaming.v1.GameServerDeploymentsServiceClient;
import java.io.IOException;

public class GetDeployment {
  public static void getGameServerDeployment(String projectId, String deploymentId)
      throws IOException {
    // String projectId = "your-project-id";
    // String deploymentId = "your-game-server-deployment-id";
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (GameServerDeploymentsServiceClient client = GameServerDeploymentsServiceClient.create()) {
      String deploymentName =
          String.format(
              "projects/%s/locations/global/gameServerDeployments/%s", projectId, deploymentId);

      GameServerDeployment deployment = client.getGameServerDeployment(deploymentName);

      System.out.println("Game Server Deployment found: " + deployment.getName());
    }
  }
}

Node.js

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.

const {
  GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function getGameServerDeployment() {
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const projectId = 'Your Google Cloud Project ID';
  // const deploymentId = 'A unique ID for the Game Server Deployment';
  const request = {
    // The full resource name
    name: client.gameServerDeploymentPath(projectId, 'global', deploymentId),
  };

  const [deployment] = await client.getGameServerDeployment(request);
  console.log(`Deployment name: ${deployment.name}`);
  console.log(`Deployment description: ${deployment.description}`);

  const createTime = deployment.createTime;
  const createDate = new Date(createTime.seconds * 1000);
  console.log(`Deployment created on: ${createDate.toLocaleDateString()}\n`);
}

getGameServerDeployment();

Python

Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.

def get_deployment(project_id, deployment_id):
    """Gets a game server deployment."""

    client = gaming.GameServerDeploymentsServiceClient()

    # Location is hard coded as global, as game server deployments can
    # only be created in global.  This is done for all operations on
    # game server deployments, as well as for its child resource types.
    request = game_server_deployments.GetGameServerDeploymentRequest(
        name=f"projects/{project_id}/locations/global/gameServerDeployments/{deployment_id}",
    )

    response = client.get_game_server_deployment(request)
    print(f"Get deployment response:\n{response}")
    return response

다음 단계