Google Cloud


gcloud command line tool

Kubernetes Engine

k8s login GCP preprod

gcloud container clusters get-credentials prod --zone europe-west1-b --project project-name–ud615

Big Table

project = project-name
instance = instance-name
$cbt ls


Load Balancing

"By default, to distribute traffic to instances, the Session Affinity is set to NONE. Google Cloud Load Balancing picks an instance based on a hash of the source IP and port, destination IP and port, and protocol. This means that incoming TCP connections are spread across instances and each new connection may go to a different instance. All packets for a connection are directed to the same instance until the connection is closed. Established connections are not taken into account when balancing.

Regardless of the session affinity setting, all packets for a connection are directed to the chosen instance until the connection is closed and have no impact on load balancing decisions for new incoming connections. This can result in imbalance between backends if long-lived TCP connections are in use.

You can choose a different Session Affinity setting if you need multiple connections from a client to go to the same instance. See sessionAffinity in the Target Pools documentation for more information." "In any of these proxy model, any traffic bound for the Service's IP:Port is proxied to an appropriate backend without the clients knowing anything about Kubernetes or Services or Pods. Client-IP based session affinity can be selected by setting service.spec.sessionAffinity to "ClientIP" (the default is "None"), and you can set the max session sticky time by setting the field service.spec.sessionAffinityConfig.clientIP.timeoutSeconds if you have already set service.spec.sessionAffinity to "ClientIP" (the default is "10800")."

Preemptible VM Instances

Deployment Manager

Deployment Manager is an infrastructure deployment service that automates the creation and management of Google Cloud Platform resources for you.

Write flexible template and configuration files and use them to create deployments that have a variety of Cloud Platform services, such as Google Cloud Storage, Google Compute Engine, and Google Cloud SQL, configured to work together.

  1. Preview Configuration (project with activated billing is needed)

  2. Alternative to deployment-manager is

custom role

### jinja
- name: custom-role
type: gcp-types/iam-v1:projects.roles
parent: projects/{{ env["project"] }}
roleId: {{ properties["roleId"] }}
title: {{ properties["title"] }}
description: {{ properties["description"] }}
stage: {{ properties["stage"] }}
includedPermissions: {{ properties["includedPermissions"] }}
### yaml
- name: app-bigtable-role
type: roles/project_custom_role.jinja
title: App Bigtable role
description: Role for managing BigTable
stage: GA
- bigtable.tables.create
- bigtable.tables.update
- bigtable.tables.checkConsistency
- bigtable.tables.generateConsistencyToken
- bigtable.tables.get
- bigtable.tables.list
- bigtable.tables.mutateRows
- bigtable.tables.readRows
- bigtable.tables.sampleRowKeys
- bigtable.appProfiles.get
- bigtable.appProfiles.list
- bigtable.clusters.get
- bigtable.clusters.list
- monitoring.metricDescriptors.get
- monitoring.metricDescriptors.list
- monitoring.timeSeries.list
- resourcemanager.projects.get

service account

### jinja
- name: {{ env['name'] }}
type: iam.v1.serviceAccount
accountId: {{ properties['name'] }}
displayName: serviceAccount-{{ properties['name'] }}
### yaml
- name: app-bigtable-sa-prod
type: accounts/service_account.jinja
name: app-prod

add roles to service accounts

- name: get-iam-policy
action: gcp-types/cloudresourcemanager-v1:cloudresourcemanager.projects.getIamPolicy
resource: project-id
- name: add-iam-policy
action: gcp-types/cloudresourcemanager-v1:cloudresourcemanager.projects.setIamPolicy
resource: project-id
policy: $(ref.get-iam-policy)
- role: projects/project-name/roles/ # custom role
- serviceAccount:[email protected]
- serviceAccount:[email protected]
- role: roles/bigtable.reader
- serviceAccount:[email protected]
- serviceAccount:[email protected]

Makefile deployment

ifeq ($(DRY_RUN), false)
# preprod
.PHONY: create-deployment
gcloud deployment-manager deployments create deployment-name --config config.yaml --project project-id $(EXTRA_ARGS)
.PHONY: update-deployment
gcloud deployment-manager deployments update deployment-name --config config.yaml --project project-id $(EXTRA_ARGS)
.PHONY: delete-deployment
gcloud deployment-manager deployments delete deployment-name --project project-id

Problems encountered

  1. Created a role bigtable.some_name , few weeks later that bigtable prefix became reserved name

  2. Created service accouunt manually, later created account and assigned role using deployment manager. Older role was also assigned and was acting like the old one. Unassigned and assigned correct role and started working.

  3. Was hard to find correct api resource for IAM. Cloud Resource Manager was the answer.


Roles, IAM, ServiceAccounts, BigTable done with Terraform

provider "google" {
project = "project-name"
### Big Table
resource "google_bigtable_instance" "bigtable-name" {
name = "bigtable-name"
cluster_id = "bigtable-name-cluster"
zone = "europe-west1-b"
num_nodes = 3
storage_type = "SSD"
### Custom role
resource "google_project_iam_custom_role" "app-bigtable-role" {
role_id = ""
title = "App BigTable Role"
description = "Role for managing BigTable"
permissions = ["bigtable.tables.create",
### service account
resource "google_service_account" "app-bigtable-sa-prod" {
account_id = "app-prod"
display_name = "serviceAccount-app-prod"
### service account
resource "google_service_account" "app-bigtable-sa-prod-reader" {
account_id = "app-prod-reader"
display_name = "serviceAccount-app-prod-reader"
### assigned custom role
resource "google_project_iam_binding" "app-prod-role" {
role = "projects/project-name/roles/"
members = ["serviceAccount:[email protected]"]
### assigned predefined BigTable role
resource "google_project_iam_binding" "app-prod-role-reader" {
role = "roles/bigtable.reader"
members = ["serviceAccount:[email protected]"]