Skip to content

Instantly share code, notes, and snippets.

@mrunalp
mrunalp / pod.json
Created May 23, 2015 00:19
/dev/shm sharing
{
"apiVersion": "v1beta2",
"desiredState": {
"manifest": {
"containers": [
{
"image": "kubernetes/pause",
"name": "hello-container1",
"ports": [
{
@mrunalp
mrunalp / mnt.c
Last active August 29, 2015 14:19
unshare and bind mount namespace
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sched.h>
#include <errno.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
@mrunalp
mrunalp / system_test.go
Created March 10, 2015 23:50
system_test.go
package system_test
import (
"io/ioutil"
"os"
"testing"
"github.com/docker/libcontainer/system"
"github.com/docker/libcontainer/selinux"
)
set -x
network_ip=10.1.0.0/16
tap_ip=10.1.0.1
new_ip=$1
net_container=$(docker run -d kubernetes/pause)
echo $net_container
pid=$(docker inspect --format "{{.State.Pid}}" ${net_container})
ipaddr=$(docker inspect --format "{{.NetworkSettings.IPAddress}}" ${net_container})
@mrunalp
mrunalp / ipvlan_setup.txt
Created February 13, 2015 18:38
ipvlan setup
1. Setup a Fedora 21 VM using virt-builder and import into virt-manager.
2. Download and compile https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.19.tar.xz with CONFIG_IPVLAN=m.
3. Copy the kernel to /boot and add it to grub using grub2-mkconfig and dracut. Reboot.
4. Steps from https://github.com/torvalds/linux/blob/master/Documentation/networking/ipvlan.txt with additional comments --
(a) Create two network namespaces - ns0, ns1
ip netns add ns0
ip netns add ns1
(b) Create two ipvlan slaves on eth0 (master device)
ip link add link eth0 ipvl0 type ipvlan mode l2
package main
import (
"fmt"
"log"
docker "github.com/fsouza/go-dockerclient"
)
func main() {
[root@localhost ~]# ovs-vsctl show
60741b68-4d89-4cee-989c-1e5a7718731e
Bridge "br0"
fail_mode: secure
Port vethd
Interface vethd
Port vethc
Interface vethc
Port "vxlan0"
Interface "vxlan0"
@mrunalp
mrunalp / userns_output
Created July 30, 2014 19:02
Sample interaction with userns shell
2014/07/30 15:00:44 Command started
sh-4.2# mount -t proc proc /proc
sh-4.2# cat /proc/self/uid_map
0 1000 1
sh-4.2# cat /proc/self/gid_map
0 1000 1
sh-4.2# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 15:00 pts/6 00:00:00 /bin/sh
root 5 1 0 15:01 pts/6 00:00:00 ps -ef
@mrunalp
mrunalp / testuserns.go
Created July 30, 2014 18:58
Test program to show user namespace POC in go
package main
import (
"log"
"os"
"os/exec"
"syscall"
)
func main() {
diff -r 9895f9e36435 src/pkg/syscall/exec_linux.go
--- a/src/pkg/syscall/exec_linux.go Thu Jun 19 10:20:01 2014 +1000
+++ b/src/pkg/syscall/exec_linux.go Wed Jul 30 14:03:39 2014 -0400
@@ -36,7 +36,7 @@
// For the same reason compiler does not race instrument it.
// The calls to RawSyscall are okay because they are assembly
// functions that do not grow the stack.
-func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, pipe int) (pid int, err Errno) {
+func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr *ProcAttr, sys *SysProcAttr, child, parent int) (pid int, err Errno) {
// Declare all variables at top in case any