Skip to content

Instantly share code, notes, and snippets.

@andy51002000
andy51002000 / private-k8s.md
Created August 1, 2022 03:42 — forked from pydevops/private-k8s.md
how to set up kubectl on laptop for private GKE cluster and on prem private cluster

HTTP tunnel

On prem k8s cluster set up with bastion vm

  1. Create a bastion vm in your data center or in cloud with connectivity set up (usually vpn) to the on prem data center.
  2. Install tinyproxy on the bastion vm and pick a random port as it would be too easy for spam bot with default 8888, set up as systemd service according to https://nxnjz.net/2019/10/how-to-setup-a-simple-proxy-server-with-tinyproxy-debian-10-buster/. Make sure it works by validating with curl --proxy http://127.0.0.1:<tinyproxy-port> https://httpbin.org/ip. And I don't use any user authentication for proxy, so I locked down the firewall rules with my laptop IP/32.
  3. Download the kubeconfig file for the k8s cluster to your laptop
  4. From your laptop, run
HTTPS_PROXY=<bastion-external-ip>:<tinyproxy-port> KUBECONFIG=my-kubeconfig kubectl get nodes
resource "google_storage_bucket" "andytest123" {
name = "ndytest123"
location = "US"
}
@andy51002000
andy51002000 / dataflow example show result.py
Created February 15, 2021 06:22
dataflow example show result
import apache_beam.runners.interactive.interactive_beam as ib
ib.show(count)
@andy51002000
andy51002000 / dataflow example.py
Created February 15, 2021 03:35
dataflow example to count words
class WordcountOptions(PipelineOptions):
@classmethod
def _add_argparse_args(cls, parser):
parser.add_argument(
'--input',
default='gs://dataflow-samples/shakespeare/kinglear.txt',
help='Path of the file to read from')
parser.add_argument(
'--output',
required=True,
@andy51002000
andy51002000 / dataflow dependencies import.py
Last active February 15, 2021 03:30
dataflow dependencies import
import re
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions
from apache_beam.io import WriteToText
@andy51002000
andy51002000 / python-es6-comparison.md
Created January 28, 2021 02:48 — forked from logicbomb421/python-es6-comparison.md
# Python3 VS ES6 syntax comparison
@andy51002000
andy51002000 / python-es6-comparison.md
Created January 28, 2021 02:44 — forked from revolunet/python-es6-comparison.md
# Python VS JavaScript ES6 syntax comparison

Python VS ES6 syntax comparison

Python syntax here : 2.7 - online REPL

Javascript ES6 via Babel transpilation - online REPL

Imports

import math
@andy51002000
andy51002000 / cloudbuild.yaml
Created June 3, 2020 08:06
check health of service in docker
- name: 'gcr.io/cloud-builders/docker'
id: build
entrypoint: bash
args:
- "-c"
- |
docker run --net=cloudbuild -p 8080:8080 --name srv -d gcr.io/${_PROJECT_NAME}/myapp:${SHORT_SHA}
API_STATUS=$(curl --fail -i --retry 3 --retry-delay 2 --retry-connrefused 'http://srv:8080/api/status' | grep HTTP | cut -d' ' -f2)
echo "API Status: $$API_STATUS"
if [ "200" != "$$API_STATUS" ]; then
@andy51002000
andy51002000 / dockerInspectCloudRunBuilder.txt
Last active May 24, 2020 07:34
An example of docker Inspect CloudRun Builder
[
{
"Id": "5f0237609d811ed5067fd73694871f0abc8fa3a8d1dc30316ff25b17180d3f3d",
"Created": "2020-05-24T07:18:53.264384127Z",
"Path": "bash",
"Args": [
"-c",
"docker inspect step_1\n\n"
],
"State": {
WITH analytics_data AS (
SELECT user_pseudo_id,
event_timestamp,
UNIX_MICROS(TIMESTAMP("2018-08-01 00:00:00", "-7:00")) AS start_day,
3600*1000*1000*24*30 AS period # 3600*1000*1000*24 表示一天
FROM `firebase-public-project.analytics_153293282.events_*`
WHERE _table_suffix BETWEEN '20180731' AND '20180829'
)