$ gcloud services enable container.googleapis.com
$ gcloud config set project {プロジェクトID}
$ gcloud config set compute/zone asia-northeast1-a Updated property [compute/zone].
$ gcloud config set compute/region asia-northeast1 Updated property [compute/region].
$ gcloud config configurations list NAME: cloudshell-10043 IS_ACTIVE: True ACCOUNT: PROJECT: test-kanehiro COMPUTE_DEFAULT_ZONE: asia-northeast1-a COMPUTE_DEFAULT_REGION: asia-northeast1
クラスター作成
gcloud container clusters create hello-cluster --machine-type=e2-micro --num-nodes=2 Creating cluster hello-cluster in asia-northeast1-a... Cluster is being health-checked (master is healthy)...done. Created [https://container.googleapis.com/v1/projects/test-kanehiro/zones/asia-northeast1-a/clusters/hello-cluster]. To inspect the contents of your cluster, go to: https://console.cloud.google.com/kubernetes/workload_/gcloud/asia-northeast1-a/hello-cluster?project=test-kanehiro kubeconfig entry generated for hello-cluster. NAME: hello-cluster LOCATION: asia-northeast1-a MASTER_VERSION: 1.23.12-gke.100 MASTER_IP: 35.200.73.36 MACHINE_TYPE: e2-micro NODE_VERSION: 1.23.12-gke.100 NUM_NODES: 2 STATUS: RUNNING
クラスタの認証情報取得
$ gcloud container clusters get-credentials hello-cluster Fetching cluster endpoint and auth data. kubeconfig entry generated for hello-cluster.
$ vi deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: labels: app: hello-server name: hello-server spec: replicas: 1 selector: matchLabels: app: hello-server template: metadata: labels: app: hello-server spec: containers: - image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 name: hello-server
$ kubectl apply -f ./deployment.yaml deployment.apps/hello-server created
$ kubectl get pod NAME READY STATUS RESTARTS AGE hello-server-69bf9bc479-wzgvp 1/1 Running 0 17s
$ kubectl get deployments,replicasets,pods --selector app=hello-server NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/hello-server 1/1 1 1 77s NAME DESIRED CURRENT READY AGE replicaset.apps/hello-server-69bf9bc479 1 1 1 77s NAME READY STATUS RESTARTS AGE pod/hello-server-69bf9bc479-wzgvp 1/1 Running 0 77s
replicasを1を2に変更
$ vi deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: labels: app: hello-server name: hello-server spec: replicas: 2 selector: matchLabels: app: hello-server template: metadata: labels: app: hello-server spec: containers: - image: us-docker.pkg.dev/google-samples/containers/gke/hello-app:1.0 name: hello-server
$ kubectl apply -f ./deployment.yaml deployment.apps/hello-server configured
$ vi service.yaml apiVersion: v1 kind: Service metadata: name: hello-server labels: app: hello-server spec: ports: - nodePort: 30934 port: 80 protocol: TCP targetPort: 8080 selector: app: hello-server type: LoadBalancer status: loadBalancer: ingress: - ip: 34.84.98.47
$ kubectl apply -f ./service.yaml service/hello-server created
$ kubectl get deployments,replicasets,pods,service --selector app=hello-server NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/hello-server 2/2 2 2 5m17s NAME DESIRED CURRENT READY AGE replicaset.apps/hello-server-69bf9bc479 2 2 2 5m17s NAME READY STATUS RESTARTS AGE pod/hello-server-69bf9bc479-msw5g 1/1 Running 0 2m48s pod/hello-server-69bf9bc479-wzgvp 1/1 Running 0 5m17s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/hello-server LoadBalancer 10.120.4.146 34.84.71.80 80:30934/TCP 58s
アクセスする
http://34.84.71.80/
@see
- https://qiita.com/8yoshiyoshi/items/99a16843e081979ff627