Skip to content

Instantly share code, notes, and snippets.

View rogerwelin's full-sized avatar
:shipit:
Gopher

Roger Welin rogerwelin

:shipit:
Gopher
View GitHub Profile
@rogerwelin
rogerwelin / middlewares.go
Last active August 20, 2019 10:19
Http middlewares in Go
package main
import (
"fmt"
"log"
"net/http"
"time"
"github.com/gorilla/mux"
)
@rogerwelin
rogerwelin / auth.go
Last active August 20, 2019 17:52
auth server
package main
import (
"fmt"
"log"
"net/http"
"time"
)
// All requests will go here first to see if client is authenticated
{
"ID": "ext-api-service",
"Name": "ext-api-service",
"Tags": [
"traefik.enable=true",
"traefik.frontend.rule=Path:/api;PathStrip:/api",
"traefik.frontend.auth.forward.address=http://localhost:5000/auth",
"traefik.frontend.auth.forward.authResponseHeaders=X-Client-ID"
],
"Address": "127.0.0.1",
@rogerwelin
rogerwelin / redis.js
Last active October 31, 2019 23:10
node-redis with lambda + elasticache
'use strict';
const redis = require('redis');
const {promisify} = require('util');
const AWSXRay = require('aws-xray-sdk-core');
const AWS = AWSXRay.captureAWS(require('aws-sdk'));
AWS.config.update({region: 'eu-west-1'});
// use the AWS variable defined above to initialize any service client that you want to trace with X-Ray
const s3 = new AWS.S3()
@rogerwelin
rogerwelin / promises.js
Last active March 6, 2020 22:08
promises, async await
const fs = require('fs');
// arrow functions.. These two are the same, but arrow functions are better
fs.readFile(fileName, (err, data) => {})
fs.readFile(fileName, function(err, data){})
//doing many things concurrent at the same time
async function getUsers() {
// need this first so use await (array)
@rogerwelin
rogerwelin / functional_operators.go
Created January 28, 2020 22:27
functional operators
package main
import (
"time"
)
type Server struct {
addr string
// default no timeout
package main
import (
"fmt"
"net/http"
"sync"
)
type HttpResult struct {
Url string
package main
import (
"fmt"
"log"
"net/http"
"github.com/pkg/errors"
)
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
metadata:
name: config
apiServer:
extraArgs:
enable-admission-plugins: "NodeRestriction,PodSecurityPolicy"

https://pmcgrath.net/using-pod-security-policies-with-kubeadm

Limits & Resources

2 types of resources: CPU and memory

Resource request: requests is what the container/pod is guaranteed to get. The scheduler will only place the pod on a node that will give it that resource. Defaults are 0.5 CPU and 256 MB RAM

Resource limits: limits ensure the container/pod never goes above a specified value. CPU will be throttled and if more memory will be consumed than the limit the OOM will kick in and the pod will be restarted.