Skip to content

Instantly share code, notes, and snippets.

@va3093
va3093 / access.md
Created Feb 4, 2021
Access k8s example
View access.md

Access K8s example

I played around with a few approaches and this seems to be the simplest. You can use this to experiment with the api.

This sets up an ubuntu box with curl pre-installed. It also creates a service account with permissions to see pods and jobs. The auth token created by this service account is stored at /var/run/secrets/kubernetes.io/serviceaccount/token

apiVersion: v1
kind: ServiceAccount
metadata:
  name: access-k8s-api
View helpful_snippets.py
# Create file logger for debugging
import logging
f_log = logging.getLogger('spam_application')
f_log.setLevel(logging.DEBUG)
fh = logging.FileHandler('/Users/wilhelm.vanderwalt/Desktop/file_logger.log')
fh.setLevel(logging.DEBUG)
f_log.addHandler(fh)
@va3093
va3093 / easy_http_mock.py
Last active Jun 26, 2017
Convenient way to mock http requests in your tests by wrapping the functionality of httppretty.
View easy_http_mock.py
import httpretty
import requests
def stub_http_request(method='GET', url=None, status=200, json={}):
def wrap(func):
@httpretty.activate
def wrapped_func(*args, **kwargs):
httpretty.register_uri(method, url,
body=f"{json}".replace("'", '"'),