CNCF Meetup
Turin, 28/11/2019,
Dario Tranchitella (prometnerion)
Part-time Cloud DevOps Engineer,
Full-Time dad of two.
I love distributed systems and whole stuff around it:
Kubernetes, Go, you know...
I'm mad at food.
Uptime
up 30 years, 90 weeks, 21 days, 18:45
1 user, load average: 2.41, 2.62, 2.45
https://github.com/kubernetes-sigs/kind
kind is a tool for running local Kubernetes clusters using Docker container "nodes". kind is primarily designed for testing Kubernetes 1.11+, initially targeting the conformance tests.
PRO
CONS
if [[ "$detected_OS" == "Ubuntu" ]]; then
sudo apt-get update
sudo apt-get -y install \
nfs-kernel-server \
virtualbox
sudo systemctl enable nfs-server
fi
if [[ "$detected_OS" == "Fedora" ]]; then
# Installing KVM Docker Machine
curl -LO https://storage.googleapis.com/minikube/releases/latest/docker-machine-driver-kvm2
chmod +x docker-machine-driver-kvm2
sudo mv docker-machine-driver-kvm2 /usr/local/bin/
# Installing system-wide dependencies
sudo dnf update
sudo dnf install -y \
nfs-utils
sudo systemctl enable rpcbind nfs-server
sudo systemctl start rpcbind nfs-server
fi
sudo touch /etc/exports
if [[ "$detected_OS" == "Ubuntu" ]]; then
SOURCES_DIR=$(dirname $(realpath .))
EXPORT="$SOURCES_DIR $(minikube ip)(rw,subtree_check,all_squash,anonuid=$(id -u),anongid=$(id -g))"
if ! $(grep -q "$EXPORT" /etc/exports); then
echo "$EXPORT" | sudo tee -a /etc/exports > /dev/null && sudo systemctl restart nfs-server
fi
minikube ssh "sudo mkdir -p /data && sudo mount -t nfs -o nfsvers=3,tcp 192.168.99.1:$SOURCES_DIR /data"
fi
if [[ "$detected_OS" == "Fedora" ]]; then
SOURCES_DIR=$(dirname $(realpath .))
EXPORT="$SOURCES_DIR $(minikube ip)(rw,subtree_check,all_squash,anonuid=$(id -u),anongid=$(id -g))"
if ! $(grep -q "$EXPORT" /etc/exports); then
echo "$EXPORT" | sudo tee -a /etc/exports > /dev/null && sudo systemctl restart nfs-server
fi
# firewalld permissions
sudo firewall-cmd --permanent --zone public --add-service mountd && \
sudo firewall-cmd --permanent --zone public --add-service rpc-bind && \
sudo firewall-cmd --permanent --zone public --add-service nfs && \
sudo firewall-cmd --reload
# SELinux flag
sudo setsebool -P nfs_export_all_rw 1
sudo exportfs -a
# Minikube provisioning
minikube ssh "sudo umount /data || true"
minikube ssh "sudo mkdir -p /data && sudo mount -t nfs -o nfsvers=3,tcp 192.168.100.1:$SOURCES_DIR /data"
fi
PRO
CONS
type Cluster struct {
TypeMeta `yaml:",inline"`
Nodes []Node `yaml:"nodes,omitempty"`
Networking Networking `yaml:"networking,omitempty"`
KubeadmConfigPatches []string `yaml:"kubeadmConfigPatches,omitempty"`
KubeadmConfigPatchesJSON6902 []PatchJSON6902 `yaml:"kubeadmConfigPatchesJSON6902,omitempty"`
ContainerdConfigPatches []string `yaml:"containerdConfigPatches,omitempty"`
ContainerdConfigPatchesJSON6902 []string `yaml:"containerdConfigPatchesJSON6902,omitempty"`
}
type Node struct {
Role NodeRole `yaml:"role,omitempty"`
Image string `yaml:"image,omitempty"`
ExtraMounts []Mount `yaml:"extraMounts,omitempty"`
ExtraPortMappings []PortMapping `yaml:"extraPortMappings,omitempty"`
KubeadmConfigPatches []string `yaml:"kubeadmConfigPatches,omitempty"`
KubeadmConfigPatchesJSON6902 []PatchJSON6902 `yaml:"kubeadmConfigPatchesJSON6902,omitempty"`
}
type PortMapping struct {
ContainerPort int32 `yaml:"containerPort,omitempty"`
HostPort int32 `yaml:"hostPort,omitempty"`
ListenAddress string `yaml:"listenAddress,omitempty"`
Protocol PortMappingProtocol `yaml:"protocol,omitempty"`
}
type Mount struct {
ContainerPath string `yaml:"containerPath,omitempty"`
HostPath string `yaml:"hostPath,omitempty"`
Readonly bool `yaml:"readOnly,omitempty"`
SelinuxRelabel bool `yaml:"selinuxRelabel,omitempty"`
Propagation MountPropagation `yaml:"propagation,omitempty"`
}
kind creates and manages local Kubernetes clusters using Docker container 'nodes'
Usage:
kind [command]
Available Commands:
build Build one of [base-image, node-image]
completion Output shell completion code for the specified shell (bash or zsh)
create Creates one of [cluster]
delete Deletes one of [cluster]
export exports one of [kubeconfig, logs]
get Gets one of [clusters, nodes, kubeconfig]
help Help about any command
load Loads images into nodes
version prints the kind CLI version
Flags:
-h, --help help for kind
--loglevel string DEPRECATED: see -v instead
-q, --quiet silence all stderr output
-v, --verbosity int32 info log verbosity
--version version for kind
Use "kind [command] --help" for more information about a command.
Creates a local Kubernetes cluster using Docker container 'nodes'
Usage:
kind create cluster [flags]
Flags:
--config string path to a kind config file
-h, --help help for cluster
--image string node docker image to use for booting the cluster
--kubeconfig string sets kubeconfig path instead of $KUBECONFIG or $HOME/.kube/config
--name string cluster context name (default "kind")
--retain retain nodes for debugging when cluster creation fails
--wait duration Wait for control plane node to be ready (default 0s)
Global Flags:
--loglevel string DEPRECATED: see -v instead
-q, --quiet silence all stderr output
-v, --verbosity int32 info log verbosity
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraMounts:
- containerPath: /mnt/data
hostPath: /path/to/your/codebase
readOnly: false
propagation: Bidirectional
extraPortMappings:
- containerPort: 80
hostPort: 80
listenAddress: 0.0.0.0
protocol: TCP
- containerPort: 443
hostPort: 443
listenAddress: 0.0.0.0
protocol: TCP
kubectl get storageclasses.storage.k8s.io
NAME PROVISIONER AGE
standard (default) kubernetes.io/host-path 161m
// https://github.com/kubernetes/kubernetes/blob/4c50ee993c82c6852eb3b3aa8dfa8ecc4bcfe330/pkg/volume/hostpath/host_path.go#L275-L282
// Create for hostPath simply creates a local /tmp/%/%s directory as a new PersistentVolume, default /tmp/hostpath_pv/%s.
// This Provisioner is meant for development and testing only and WILL NOT WORK in a multi-node cluster.
func (r *hostPathProvisioner) Provision(selectedNode *v1.Node, allowedTopologies []v1.TopologySelectorTerm) (*v1.PersistentVolume, error) {
if util.CheckPersistentVolumeClaimModeBlock(r.options.PVC) {
return nil, fmt.Errorf("%s does not support block volume provisioning", r.plugin.GetPluginName())
}
fullpath := fmt.Sprintf("/tmp/%s/%s", r.basePath, uuid.NewUUID())
but kind load docker-image FTW!
but #kind on Kubernetes Slack is very much alive!