Skip to content

Instantly share code, notes, and snippets.

View anfernee's full-sized avatar

Yongkun Anfernee Gui anfernee

  • Google
  • San Francisco Bay area
View GitHub Profile
filter := new(property.WaitFilter)
filter.Add(dc.VmFolder, "VirtualMachine", []string{"runtime.host"})
return property.WaitForUpdates(ctx, p, filter, func(updates []types.ObjectUpdate) bool {
fmt.Println("updates: ", updates)
return false // keep waiting
})
@anfernee
anfernee / k8s_test.go
Created August 24, 2018 20:32
testenv for k8s
testenv := test.NewTestEnvironment()
shutdown := make(chan struct{})
cfg := testenv.Start(apis.GetAllApiBuilders(), openapi.GetOpenAPIDefinitions)
si := sharedinformers.NewSharedInformers(cfg, shutdown)
defer func() {
testenv.Stop()
close(shutdown)
}()
@anfernee
anfernee / calico-debug.sh
Last active November 15, 2018 18:58
calico-debug.sh
# Source this at node as root
# install calicoctl
curl -O -L https://github.com/projectcalico/calicoctl/releases/download/v2.0.7/calicoctl
chmod +x calicoctl
mv calicoctl /usr/local/bin
# Imagine dstype is kubernetes
# otherwise need this: ETCD_ENDPOINTS=http://myhost1:2379
export DATASTORE_TYPE=kubernetes
@anfernee
anfernee / katran.log
Created November 21, 2018 07:26
katran-failed
# sudo ./build/example_grpc/katran_server_grpc -balancer_prog ./deps/linux/bpfprog/bpf/balancer_kern.o -default_mac 52:54:00:12:35:02 -forwarding_cores=0 -healthchecker_prog ./deps/linux/bpfprog/bpf/healthchecking_ipip.o -intf=lo -ipip_intf=ipip0 -ipip6_intf=ipip60 -lru_size=10000 -v=4 2>&1 >server.log
I1120 21:21:01.783613 20922 katran_server.cpp:111] size of forwarding cores vector is 1
I1120 21:21:01.783656 20922 katran_server.cpp:113] size of numa nodes vector is 0
I1120 21:21:01.783850 20922 KatranGrpcService.cpp:67] Starting Katran
I1120 21:21:01.783865 20922 KatranLb.cpp:215] per core lru size: 10000
I1120 21:21:01.784356 20922 BpfLoader.cpp:452] section name: .strtab index: 1
data: 0x5565272ddb60 size: 970
link: 0
E1120 21:21:01.784365 20922 BpfLoader.cpp:166] Can't read section size for index: 2
@anfernee
anfernee / server.go
Created January 16, 2019 01:15
verify Shutdown() and ListenAndServe behavior.
package main
import (
"context"
"log"
"net/http"
"time"
)
func delayedHandler(w http.ResponseWriter, r *http.Request) {
@anfernee
anfernee / iptables -L
Last active March 1, 2019 08:35
k8s node iptables
Chain INPUT (policy DROP)
target prot opt source destination
KUBE-EXTERNAL-SERVICES all -- anywhere anywhere ctstate NEW /* kubernetes externally-visible service portals */
KUBE-FIREWALL all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere
ACCEPT udp -- anywhere anywhere
@anfernee
anfernee / iptables-save
Created March 2, 2020 05:56
netd-iptables
-A PREROUTING -m comment --comment "kubernetes service portals" -j KUBE-SERVICES
-A OUTPUT -m comment --comment "kubernetes service portals" -j KUBE-SERVICES
-A POSTROUTING -m comment --comment "kubernetes postrouting rules" -j KUBE-POSTROUTING
-A POSTROUTING -m comment --comment "ip-masq: ensure nat POSTROUTING directs all non-LOCAL destination traffic to our custom IP-MASQ chain" -m addrtype ! --dst-type LOCAL -j IP-MASQ
-A IP-MASQ -d 169.254.0.0/16 -m comment --comment "ip-masq: local traffic is not subject to MASQUERADE" -j RETURN
-A IP-MASQ -d 10.0.0.0/8 -m comment --comment "ip-masq: RFC 1918 reserved range is not subject to MASQUERADE" -j RETURN
-A IP-MASQ -d 172.16.0.0/12 -m comment --comment "ip-masq: RFC 1918 reserved range is not subject to MASQUERADE" -j RETURN
-A IP-MASQ -d 192.168.0.0/16 -m comment --comment "ip-masq: RFC 1918 reserved range is not subject to MASQUERADE" -j RETURN
-A IP-MASQ -d 240.0.0.0/4 -m comment --comment "ip-masq: RFC 5735 reserved range is not subject to MASQUERADE" -j RE
@anfernee
anfernee / role.yaml
Created March 7, 2020 23:29
kube-keepalived-config
# kubectl exec kube-keepalived-vip-2djmq cat /etc/keepalived/keepalived.conf
global_defs {
vrrp_version 3
vrrp_iptables KUBE-KEEPALIVED-VIP
}
#Check if the VIP list is empty
vrrp_instance vips {
# Node status
status:
addresses:
- address: 10.128.15.209
type: InternalIP
- address: 104.198.153.58
type: ExternalIP
- address: gke-cluster-4-default-pool-606b8fc7-jqmx.c.ygui-gke.google.com.internal
type: InternalDNS
@anfernee
anfernee / 01-trace.md
Created May 8, 2020 05:08
Kernel-Note