WARNING: Currently VPC-native is not the default mode during cluster creation. In the future, this will become the default mode and can be disabled using --no-enable-ip-ali as flag. Use --[no-]enable-ip-alias flag to suppress this warning. WARNING: Newly created clusters and node-pools will have node auto-upgrade enabled by default. This can be disabled using the --no-enable-autoupgrade flag. WARNING: Starting in 1.12, default node pools in new clusters will have their legacy Compute Engine instance metadata endpoints disabled by default. To create a cluster with legacy instance metadata endpoints disabled in the default node pool, run clusters create with the flag --metadata disable-legacy-endpoints=true. WARNING: Your Pod address range (--cluster-ipv4-cidr) can accommodate at most 1008 node(s). This will enable the autorepair feature for nodes. Please see https://cloud.google.com/kubernetes-engine/docs/node-auto-repair for more information on node autorepairs. ERROR: (gcloud.container.clusters.create) ResponseError: code=403, message=Kubernetes Engine API is not enabled for this project. Please ensure it is enabled in Google Cloud Console and try again: visit https://console.cloud.google.com/apis/api/container.googleapis.com/overview?project=elated-ranger-26 to do so.
hello-app ver 1.0 이다. dockerfile 을 확인하면 컨테이너 설정을 확인할수 있다.
kubectl expose 를 이용하여 생성한 파일을 노출한다.
@cloudshell:~/hello-app (jth3434-197516)$ kubectl get pods NAME READY STATUS RESTARTS AGE hello-server-64db4d4dc7-xtrcd 1/1 Running 0 12m @cloudshell:~/hello-app (jth3434-197516)$ kubectl get service hello-server NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE hello-server LoadBalancer 10.35.255.80 35.223.145.93 80:30201/TCP 5m30s
그리고 get pads 으로 pads 의 상태를 확인하고 서비스를 확인해서 정상적으로 external-ip로 접속했을때 접속이 되면 정상이다.
dellpa34@cloudshell:~/docs-examples/subnetwork_basic$ terraform plan Error: Error locking state: Error acquiring the state lock: resource temporarily unavailable Lock Info: ID: 640725d0-1fad-c74e-7cff-35baf4c72937 Path: terraform.tfstate Operation: OperationTypeApply Who: dellpa34@cs-6000-devshell-vm-3de0c123-93a9-4a2f-a584-d94918d8801a Version: 0.12.18 Created: 2020-01-04 12:07:10.301086954 +0000 UTC Info: Terraform acquires a state lock to protect the state from being written by multiple users at the same time. Please resolve the issue above and try again. For most commands, you can disable locking with the "-lock=false" flag, but this is not recommended.
테스트중에 캔슬 한번했더니 프로세스가 종료되지 않아서 자꾸 -lock=false 옵션을 주라고 떳다. 귀찮아서 그냥 죽였다. kill -9 4120
Provider "registry.terraform.io/-/google" v1.19.1 is not compatible with Terraform 0.12.18. Provider version 2.5.0 is the earliest compatible version. Select it with the following version constraint:
version = "~> 2.5" Terraform checked all of the plugin versions matching the given constraint: ~> 1.19.0 Consult the documentation for this provider for more information on compatibility between provider and Terraform versions. Downloading plugin for provider "random" (hashicorp/random) 2.2.1… Error: incompatible provider version
error 는 backing_file.tf 파일에서 발생하고 있었다. 간단하게 version 차이..
provider.google v2.20.1 로 1.19보다 많이 높은 상태였다. 일단 진행해 보기로 했으니.. backing_file.tf 수정
provider "google" { version = "~> 1.19.0" region = "us-central1" zone = "us-central1-c" }
provider "google" { version = "~> 2.5" region = "us-central1" zone = "us-central1-c" }
수정후에 다시 terraform init 을 실행 하였다.
Initializing provider plugins… Checking for available provider plugins… Downloading plugin for provider "google" (hashicorp/google) 2.20.1… Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary.
정상적으로 실행 되는것을 확인하였다.
init 후에 apply 하니 다시 Warning 과 함께 error 가 발생하였다.
Warning: Interpolation-only expressions are deprecated on main.tf line 9, in resource "google_compute_instance" "instance": 9: image = "${data.google_compute_image.debian_image.self_link}"Error: Error loading zone 'us-central1-a': googleapi: Error 403: Access Not Configured. Compute Engine API has not been used in project 45002 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/compute.googleapis.com/overview?project=304102002 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry., accessNotConfigured on main.tf line 1, in resource "google_compute_instance" "instance": 1: resource "google_compute_instance" "instance" {
이건 이전에도 겪은 케이스 같다...functions api 셋팅할때 발생한 거였는데...googleapi 관련 에러다. cloudshell 에서 컴퓨팅쪽의 api를 사용할 수 없어서 발생하는 에러로 로그에 보이는 페이지로 이동해서 그냥 허용해 준다.
Enter a value: yes google_compute_instance.instance: Creating… google_compute_instance.instance: Still creating… [10s elapsed] google_compute_instance.instance: Creation complete after 10s [id=vm-instance-optimum-badger] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
허용후에 다시 terraform apply 를 치면 정상적으로 실행이 된다. 그럼 확인해 보자.
인스턴스가 생성이 됬다. 그렇다면 이젠 간단히 생성하는것 까지 완료했으므로. 이젠 기본 템플릿을 이용한 구성을 만들것이다. 생성한 테라폼은 terraform destroy 명령어로 삭제 했다.
google_compute_instance.instance: Destroying… [id=vm-instance-optimum-badger] google_compute_instance.instance: Still destroying… [id=vm-instance-optimum-badger, 10s elapsed] google_compute_instance.instance: Still destroying… [id=vm-instance-optimum-badger, 20s elapsed] google_compute_instance.instance: Still destroying… [id=vm-instance-optimum-badger, 30s elapsed] google_compute_instance.instance: Destruction complete after 38s random_pet.suffix: Destroying… [id=optimum-badger] random_pet.suffix: Destruction complete after 0s
정상적으로 삭제되는것을 확인할수 있었다.
gcp cloud shell 에서 terraform 을 사용하는 방법을 테스트해 보았다. 다음엔 VPC 구성과 인스턴스 그룹 생성 로드벨런서 구성까지 한방에 진행할것이다.
여담으로 cloud shell은 진짜 강력한 도구이다.
스크린샷과 같이 shell을 지원하면서 동시에 에디터도 지원한다.
vi 에 익숙한 나같은경우에는 그냥 vi 로 작업하지만 익숙하지 않은 사용자의 경우에는 우와할정도다..