Skip to content

Instantly share code, notes, and snippets.

@s1061123
Last active July 4, 2024 08:35
Show Gist options
  • Save s1061123/c0b857ec1a399c1e174531c0b826a81c to your computer and use it in GitHub Desktop.
Save s1061123/c0b857ec1a399c1e174531c0b826a81c to your computer and use it in GitHub Desktop.
Kind with Multus log
## Create 3-node environment config
[tohayash@tohayash-lab tmp]$ cat << EOF > config-3node.yml
kind: Cluster
apiVersion: kind.sigs.k8s.io/v1alpha3
nodes:
- role: control-plane
- role: worker
- role: worker
# Note: uncomment if you install cni plugin by yourself
#networking:
# disableDefaultCNI: true
EOF
## Create cluster
[tohayash@tohayash-lab tmp]$ kind create cluster --config config-3node.yml
Creating cluster "kind" ...
✓ Ensuring node image (kindest/node:v1.17.0) 🖼
✓ Preparing nodes 📦 📦 📦
✓ Writing configuration 📜
✓ Starting control-plane 🕹️
✓ Installing CNI 🔌
✓ Installing StorageClass 💾
✓ Joining worker nodes 🚜
Set kubectl context to "kind-kind"
You can now use your cluster with:
kubectl cluster-info --context kind-kind
Thanks for using kind! 😊
## Load kubeconfig
[tohayash@tohayash-lab tmp]$ kind export kubeconfig
Set kubectl context to "kind-kind"
## get node
[tohayash@tohayash-lab tmp]$ kubectl get node
NAME STATUS ROLES AGE VERSION
kind-control-plane Ready master 80s v1.17.0
kind-worker Ready <none> 47s v1.17.0
kind-worker2 Ready <none> 47s v1.17.0
## install multus
[tohayash@tohayash-lab tmp]$ kubectl create -f https://raw.githubusercontent.com/intel/multus-cni/master/images/multus-daemonset.yml
customresourcedefinition.apiextensions.k8s.io/network-attachment-definitions.k8s.cni.cncf.io created
clusterrole.rbac.authorization.k8s.io/multus created
clusterrolebinding.rbac.authorization.k8s.io/multus created
serviceaccount/multus created
configmap/multus-cni-config created
daemonset.apps/kube-multus-ds-amd64 created
daemonset.apps/kube-multus-ds-ppc64le created
## get koko
[tohayash@tohayash-lab tmp]$ curl -LO https://github.com/redhat-nfvpe/koko/releases/download/v0.82/koko_0.82_linux_amd64
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 611 0 611 0 0 1253 0 --:--:-- --:--:-- --:--:-- 1254
100 14.6M 100 14.6M 0 0 2652k 0 0:00:05 0:00:05 --:--:-- 3233k
[tohayash@tohayash-lab kind]$ chmod +x koko_0.82_linux_amd64
## Create veth interface between kind-woker and kind-worker2
[tohayash@tohayash-lab tmp]$ sudo ./koko_0.82_linux_amd64 -d kind-worker,eth1 -d kind-worker2,eth1
Create veth...done
## install CNI reference plugin from github
[tohayash@tohayash-lab tmp]$ cat << EOF > cni-install.yml
---
kind: ConfigMap
apiVersion: v1
metadata:
name: cni-install-sh
namespace: kube-system
data:
install_cni.sh: |
cd /tmp
wget https://github.com/containernetworking/plugins/releases/download/v0.8.5/cni-plugins-linux-amd64-v0.8.5.tgz
cd /host/opt/cni/bin
tar xvfzp /tmp/cni-plugins-linux-amd64-v0.8.5.tgz
sleep infinite
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: install-cni-plugins
namespace: kube-system
labels:
name: cni-plugins
spec:
selector:
matchLabels:
name: cni-plugins
template:
metadata:
labels:
name: cni-plugins
spec:
hostNetwork: true
nodeSelector:
kubernetes.io/arch: amd64
tolerations:
- operator: Exists
effect: NoSchedule
containers:
- name: install-cni-plugins
image: alpine
command: ["/bin/sh", "/scripts/install_cni.sh"]
resources:
requests:
cpu: "100m"
memory: "50Mi"
limits:
cpu: "100m"
memory: "50Mi"
securityContext:
privileged: true
volumeMounts:
- name: cni-bin
mountPath: /host/opt/cni/bin
- name: scripts
mountPath: /scripts
volumes:
- name: cni-bin
hostPath:
path: /opt/cni/bin
- name: scripts
configMap:
name: cni-install-sh
items:
- key: install_cni.sh
path: install_cni.sh
EOF
[tohayash@tohayash-lab tmp]$ kubectl create -f cni-install.yml
configmap/cni-install-sh created
daemonset.apps/install-cni-plugins created
## create two centos with macvlan!
[tohayash@tohayash-lab tmp]$ cat << EOF > centos-macvlan.yml
---
apiVersion: "k8s.cni.cncf.io/v1"
kind: NetworkAttachmentDefinition
metadata:
name: centos-runtimeconfig-def
spec:
config: '{
"cniVersion": "0.3.1",
"plugins": [
{
"type": "macvlan",
"capabilities": { "ips": true },
"master": "eth1",
"mode": "bridge",
"ipam": {
"type": "static"
}
}, {
"type": "tuning"
} ]
}'
---
apiVersion: v1
kind: Pod
metadata:
name: centos-worker1
annotations:
k8s.v1.cni.cncf.io/networks: '[
{ "name": "centos-runtimeconfig-def",
"ips": [ "10.1.1.11/24" ] }
]'
spec:
containers:
- name: centos-worker1
image: docker.io/centos/tools:latest
command:
- /sbin/init
securityContext:
privileged: true
nodeSelector:
kubernetes.io/hostname: kind-worker
---
apiVersion: v1
kind: Pod
metadata:
name: centos-worker2
annotations:
k8s.v1.cni.cncf.io/networks: '[
{ "name": "centos-runtimeconfig-def",
"ips": [ "10.1.1.12/24" ] }
]'
spec:
containers:
- name: centos-worker2
image: docker.io/centos/tools:latest
command:
- /sbin/init
securityContext:
privileged: true
nodeSelector:
kubernetes.io/hostname: kind-worker2
EOF
[tohayash@tohayash-lab tmp]$ kubectl create -f centos-macvlan.yml
networkattachmentdefinition.k8s.cni.cncf.io/centos-runtimeconfig-def created
pod/centos-worker1 created
pod/centos-worker2 created
[tohayash@tohayash-lab tmp]$ kubectl get pod
NAME READY STATUS RESTARTS AGE
centos-worker1 0/1 ContainerCreating 0 13s
centos-worker2 0/1 ContainerCreating 0 13s
[tohayash@tohayash-lab tmp]$ kubectl get pod
NAME READY STATUS RESTARTS AGE
centos-worker1 1/1 Running 0 14s
centos-worker2 1/1 Running 0 14s
## check interface and ping
[tohayash@tohayash-lab tmp]$ kubectl exec -it centos-worker1 bash
[root@centos-worker1 /]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: eth0@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 7a:7e:57:70:99:f2 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 10.244.2.4/24 brd 10.244.2.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::787e:57ff:fe70:99f2/64 scope link
valid_lft forever preferred_lft forever
4: net1@if391: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether f6:ba:be:b0:4a:5a brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 10.1.1.11/24 brd 10.1.1.255 scope global net1
valid_lft forever preferred_lft forever
inet6 fe80::f4ba:beff:feb0:4a5a/64 scope link
valid_lft forever preferred_lft forever
[root@centos-worker1 /]# exit
exit
[tohayash@tohayash-lab tmp]$ kubectl exec -it centos-worker2 bash
[root@centos-worker2 /]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
3: eth0@if2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether da:0f:cc:ca:bc:14 brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 10.244.1.4/24 brd 10.244.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::d80f:ccff:feca:bc14/64 scope link
valid_lft forever preferred_lft forever
4: net1@if390: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether d2:e7:b1:f3:19:3d brd ff:ff:ff:ff:ff:ff link-netnsid 0
inet 10.1.1.12/24 brd 10.1.1.255 scope global net1
valid_lft forever preferred_lft forever
inet6 fe80::d0e7:b1ff:fef3:193d/64 scope link
valid_lft forever preferred_lft forever
[root@centos-worker2 /]# ping 10.1.1.11
PING 10.1.1.11 (10.1.1.11) 56(84) bytes of data.
64 bytes from 10.1.1.11: icmp_seq=1 ttl=64 time=0.159 ms
64 bytes from 10.1.1.11: icmp_seq=2 ttl=64 time=0.030 ms
64 bytes from 10.1.1.11: icmp_seq=3 ttl=64 time=0.032 ms
^C
--- 10.1.1.11 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2069ms
rtt min/avg/max/mdev = 0.030/0.073/0.159/0.061 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment