Getting Started with Kubernetes: Part 1 - Setting Up The Development Environment
Get Started with Kubernetes using Minikube and VirtualBox
Download & Install MiniKube
You will need a few tools to get Kubernetes running on your workstation:
- kubectl is the Kubernetes command-line interface. Throughout this book, you will be using it to interact with Kubernetes.
- minikube is a command that manages Kubernetes on your local machine. It handles all the hard stuff, so you can get started with Kubernetes straight away.
- docker, the minikube virtual machine, has the Docker daemon running internally, but you might need the Docker command line installed on your workstation if you want to interact with it directly.
It is best to use Minikube in conjunction with a virtual machine. Using VirtualBox with minikube works perfect for this scenario.
- VirtualBox: https://www.virtualbox.org/wiki/Downloads
Install on MacOS
$ brew install kubernetes-cli
Install on Linux
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 $ curl -LO https://dl.k8s.io/v1.10.6/bin/linux/amd64/kubectl $ chmod +x minikube kubectl $ mv minikube kubectl /usr/local/bin/
Once everything is installed, test minikube by starting it via terminal.
$ minikube start
You should see an output similar to the following:
┌───[~] └── ˉ\_(ツ)_/ˉ $ minikube start ?? minikube v1.11.0 on Darwin 10.15.4 ? Using the docker driver based on existing profile ?? Starting control plane node minikube in cluster minikube ?? Restarting existing docker container for "minikube" ... ?? Preparing Kubernetes v1.18.3 on Docker 19.03.2 ... ? kubeadm.pod-network-cidr=10.244.0.0/16 ?? Verifying Kubernetes components... ?? Enabled addons: default-storageclass, storage-provisioner ?? Done! kubectl is now configured to use "minikube" ? /usr/local/bin/kubectl is version 1.16.6-beta.0, which may be incompatible with Kubernetes 1.18.3.
?? You can also use 'minikube kubectl -- get pods' to invoke a matching version
You can use the flags --cpus and/or --memory to customize how much of your system resources are used for the Minikube VM.
Confirm installation/configuration by checking the kubectl config file ~/.kube/config which defines kubectl contexts. A context links to a cluster and a user object. The cluster defines how.
The "minikube start" command creates a kubectl context pointing to the API server running within our Minikube VM, which is correctly configured with a user that will allow access to Kubernetes.
┌───[~] └── ˉ\_(ツ)_/ˉ $ cat ~/.kube/config apiVersion: v1 clusters: - cluster: certificate-authority-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUN5RENDQWJDZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKY201bGRHVnpNQjRYRFRFNU1URXlNVEl6TVRjMU5Gb1hEVEk1TVRFeE9ESXpNVGMxTkZvd0ZURVRNQkVHQTFVRQpBeE1LYTNWaVpYSnVaWFJsY3pDQ0FTSXdEUVlKS29aSWh2Y05BUUVCQlFBRGdnRVBBRENDQVFvQ2dnRUJBS3JsCnpNS09aOFBnQ= server: https://kubernetes.docker.internal:6443 name: docker-desktop - cluster: certificate-authority: /Users/dcurtis/.minikube/ca.crt server: https://127.0.0.1:32768 name: minikube contexts: - context: cluster: docker-desktop user: docker-desktop name: docker-desktop - context: cluster: docker-desktop user: docker-desktop name: docker-for-desktop - context: cluster: minikube user: minikube name: minikube current-context: minikube kind: Config preferences: {} users: - name: docker-desktop user: client-certificate-data: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM5RENDQWR5Z0F3SUJBZ0lJSU1PTlF5RGo3MGt3RFFZSktvWklodmNOQVFFTEJRQXdGVEVUTUJFR0ExVUUKQXhNS2EzVmlaWEp1WlhSbGN6QWVGdzB4T1RFeE1qRXlNekUzTlRSYUZ3MHlNVEEyTURjeE16UXhNelJhTURZeApGekFWQmdOVkJBb1REbk41YzNSbGJUcH client-key-data: LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFb2dJQkFBS0NBUUVBeSs5NEg1WTdOK1E1a1BqM3ZpWlArM0UzNkduYzROUzBiTVNJM1lVemluT2EwbkFZCjFGc1FRUC9IUXgwNlY2RVJaRTM5K2tXWC8yYmNaaG53QVhpc1g4cHlXWWhLS3BNVWVJRkRQYkZxRTJjeVhpcGQKeVlnYytSQ1lOblNNT3YvVGVwR0dFZUtu== - name: minikube user: client-certificate: /Users/dcurtis/.minikube/profiles/minikube/client.crt
client-key: /Users/dcurtis/.minikube/profiles/minikube/client.key
If you misconfigure any contexts and want to reset them, you can run the following
$ kubectl config use-context minikube
Let's check the version our our Kubernetes
┌───[~] └── ˉ\_(ツ)_/ˉ $ kubectl version Client Version: version.Info{Major:"1", Minor:"16+", GitVersion:"v1.16.6-beta.0", GitCommit:"e7f962ba86f4ce7033828210ca3556393c377bcc", GitTreeState:"clean", BuildDate:"2020-01-15T08:26:26Z", GoVersion:"go1.13.5", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.3", GitCommit:"2e7996e3e2712684bc73f0dec0200d64eec7fe40", GitTreeState:"clean", BuildDate:"2020-05-20T12:43:34Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Let's try interacting with our new kubernetes cluster with some basic kubectl commands.
┌───[~] └── ˉ\_(ツ)_/ˉ $ kubectl get nodes NAME STATUS ROLES AGE VERSION
minikube Ready master 2d14h v1.18.3
Now that we have info about our node, we can get more info on the node using "kubectl describe node/minikube"
┌───[~] └── ˉ\_(ツ)_/ˉ $ kubectl describe node/minikube Name: minikube Roles: master Labels: beta.kubernetes.io/arch=amd64 beta.kubernetes.io/os=linux kubernetes.io/arch=amd64 kubernetes.io/hostname=minikube kubernetes.io/os=linux minikube.k8s.io/commit=57e2f55f47effe9ce396cea42a1e0eb4f611ebbd minikube.k8s.io/name=minikube minikube.k8s.io/updated_at=2020_06_04T17_46_27_0700 minikube.k8s.io/version=v1.11.0 node-role.kubernetes.io/master= Annotations: kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock node.alpha.kubernetes.io/ttl: 0 volumes.kubernetes.io/controller-managed-attach-detach: true CreationTimestamp: Thu, 04 Jun 2020 17:46:24 -0600 Taints: <none> Unschedulable: false Conditions: Type Status LastHeartbeatTime LastTransitionTime Reason Message ---- ------ ----------------- ------------------ ------ ------- MemoryPressure False Sun, 07 Jun 2020 08:11:40 -0600 Thu, 04 Jun 2020 17:46:21 -0600 KubeletHasSufficientMemory kubelet has sufficient memory available DiskPressure False Sun, 07 Jun 2020 08:11:40 -0600 Thu, 04 Jun 2020 17:46:21 -0600 KubeletHasNoDiskPressure kubelet has no disk pressure PIDPressure False Sun, 07 Jun 2020 08:11:40 -0600 Thu, 04 Jun 2020 17:46:21 -0600 KubeletHasSufficientPID kubelet has sufficient PID available Ready True Sun, 07 Jun 2020 08:11:40 -0600 Thu, 04 Jun 2020 17:46:38 -0600 KubeletReady kubelet is posting ready status Addresses: InternalIP: 172.17.0.2 Hostname: minikube Capacity: cpu: 8 ephemeral-storage: 61255492Ki hugepages-1Gi: 0 hugepages-2Mi: 0 memory: 2038184Ki pods: 110 Allocatable: cpu: 8 ephemeral-storage: 61255492Ki hugepages-1Gi: 0 hugepages-2Mi: 0 memory: 2038184Ki pods: 110 System Info: Machine ID: 928a629d200c448d9b9a24d8edbd88f2 System UUID: 65d75a15-bba6-44a3-b336-1b4cbb598ba4 Boot ID: 2a61ae69-2806-4f5c-9270-ac275cc38b51 Kernel Version: 4.19.76-linuxkit OS Image: Ubuntu 19.10 Operating System: linux Architecture: amd64 Container Runtime Version: docker://19.3.2 Kubelet Version: v1.18.3 Kube-Proxy Version: v1.18.3 PodCIDR: 10.244.0.0/24 PodCIDRs: 10.244.0.0/24 Non-terminated Pods: (8 in total) Namespace Name CPU Requests CPU Limits Memory Requests Memory Limits AGE --------- ---- ------------ ---------- --------------- ------------- --- kube-system coredns-66bff467f8-n8lps 100m (1%) 0 (0%) 70Mi (3%) 170Mi (8%) 2d14h kube-system coredns-66bff467f8-nrbsj 100m (1%) 0 (0%) 70Mi (3%) 170Mi (8%) 2d14h kube-system etcd-minikube 0 (0%) 0 (0%) 0 (0%) 0 (0%) 28m kube-system kube-apiserver-minikube 250m (3%) 0 (0%) 0 (0%) 0 (0%) 28m kube-system kube-controller-manager-minikube 200m (2%) 0 (0%) 0 (0%) 0 (0%) 2d14h kube-system kube-proxy-djztt 0 (0%) 0 (0%) 0 (0%) 0 (0%) 2d14h kube-system kube-scheduler-minikube 100m (1%) 0 (0%) 0 (0%) 0 (0%) 2d14h kube-system storage-provisioner 0 (0%) 0 (0%) 0 (0%) 0 (0%) 2d14h Allocated resources: (Total limits may be over 100 percent, i.e., overcommitted.) Resource Requests Limits -------- -------- ------ cpu 750m (9%) 0 (0%) memory 140Mi (7%) 340Mi (17%) ephemeral-storage 0 (0%) 0 (0%) Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Starting 28m kubelet, minikube Starting kubelet. Normal NodeAllocatableEnforced 28m kubelet, minikube Updated Node Allocatable limit across pods Normal NodeHasSufficientMemory 28m (x8 over 28m) kubelet, minikube Node minikube status is now: NodeHasSufficientMemory Normal NodeHasNoDiskPressure 28m (x7 over 28m) kubelet, minikube Node minikube status is now: NodeHasNoDiskPressure Normal NodeHasSufficientPID 28m (x8 over 28m) kubelet, minikube Node minikube status is now: NodeHasSufficientPID Warning readOnlySysFS 28m kube-proxy, minikube CRI error: /sys is read-only: cannot modify conntrack limits, problems may arise later (If running Docker, see docker issue #24000)
Normal Starting 28m kube-proxy, minikube Starting kube-proxy.
Next up: Creating Docker containers inside our Kubernetes cluster