Posts

Showing posts with the label k8s

Kubernetes: Declarative vs Imperative (Nginx Example on Minikube)

Image
In this post, I am going to run a Nginx example on Minikube in two ways: 1. declarative: kubectl apply -f [yaml] 2. imperative: kubectl create & expose declarative: kubectl apply -f [yaml] With a declarative way, you can define the resources as yamls and apply them. This is preferable in a long run, but could be tedious if you just want to run it as a test. % cat deploy.yaml apiVersion: apps/v1 kind: Deployment metadata:   labels:     app: nginx   name: nginx spec:   replicas: 1   selector:     matchLabels:       app: nginx   template:     metadata:       labels:         app: nginx     spec:       containers:       - image: nginx         name: nginx % cat service.yaml apiVersion: v1 kind: Service metadata:   labels:     app: nginx   name: nginx spec:   ports:   - port: 80     proto...

kubectx & kubens: Quick Start

This post shows examples of kubectx & kubens. install % brew install kubectx This will install both kubectx and kubens. kubectx kubectx help manage k8s contexts. % kubectx -h USAGE:   kubectx                       : list the contexts   kubectx <NAME>                : switch to context <NAME>   kubectx -                     : switch to the previous context   ... Listing the contexts is as simple as follows: % kubectl config get-contexts CURRENT   NAME        CLUSTER     AUTHINFO    NAMESPACE *         kind-kind   kind-kind   kind-kind              minikube    minikube    minikube    default % kubectx kind-kind minikube Change the context:...

Minikube Installation for M1 Mac

Image
In this post, I am going to try Minikube on Mac with M1 Chip. what is minikube Minikube is k8s tool running on a local machine. See also kind  for multi cluster implementation for local k8s. install % curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-darwin-arm64 % install minikube-darwin-arm64 /usr/local/bin/minikube % minikube version  minikube version: v1.20.0  Note: Installing with brew fails due to a different binary as of 2021-05-24. % brew install minikube % minikube version ❌  Exiting due to MK_WRONG_BINARY_M1: You are trying to run amd64 binary on M1 system. Please use darwin/arm64 binary instead (Download at https://github.com/kubernetes/minikube/releases/download/v1.20.0/minikube-darwin-amd64.) % brew uninstall minikube start The default driver 'virtualbox' is not supported on M1, but you can use 'docker' driver:  https://minikube.sigs.k8s.io/docs/drivers/docker/  . Make sure docker is running, and then specify the driver ...

kind (multi-node k8s cluster): Quick Start on Mac

This post shows an example usage of kind  on Mac. what is kind? kind lets you create a k8s cluster with multiple nodes on docker. You need docker & kubectl to run it. install % docker -v Docker version 20.10.5, build 55c4c88 % kubectl version ... v1.19.7 ... % brew install kind % kind --version kind version 0.11.0 one-node cluster You can create a one-node cluster by default. The initial creation may take a few minutes longer to load the image. % kind create cluster % kubectl get node NAME                 STATUS     ROLES                  AGE   VERSION kind-control-plane   NotReady   control-plane,master   30s   v1.21.1 % kind delete cluster multi-node cluster Passing a config file (--config) lets you create a cluster with multiple nodes. The following example will create 3 controle-planes & 3 workers. % cat kind.yaml...

Google Kubernetes Engine (GKE) Quick Start on CLI

Google Cloud provides a nice quickstart guide for GKE: https://cloud.google.com/kubernetes-engine/docs/quickstart This post follows the steps on CLI. You need to install gcloud & kubectl as a pre-requisite. # enable GKE % gcloud services enable container.googleapis.com % gcloud services list | grep -i 'kube' container.googleapis.com          Kubernetes Engine API # config gcloud % gcloud config set project YOUR_PROJECT_ID % gcloud config set compute/zone us-west1-a % gcloud config set compute/region us-west1 # create cluster (few minutes) % gcloud container clusters create hello-cluster --num-nodes=1 % gcloud container clusters list NAME           LOCATION    MASTER_VERSION   MASTER_IP     MACHINE_TYPE  NODE_VERSION     NUM_NODES  STATUS hello-cluster  us-west1-a  1.18.17-gke.100  35.230.17.63  e2-medium     1.18.17-gke.100  1...

etcd (v3.4): Quick Start on Mac

This post describes how to use etcd on Mac. what is etcd? etcd is an open source KVS. It is also one of k8s core components. This YouTube video from IBM Cloud is great to understand its features: https://www.youtube.com/watch?v=OmphHSaO1sE install %   brew install etcd % etcd --version etcd Version: 3.4.15 Git SHA: Not provided (use ./build instead of go build) Go Version: go1.16 Go OS/Arch: darwin/amd64 % etcdctl version   etcdctl version: 3.4.15 API version: 3.4 run $ etcd usage The following lists the available command options (version 3.4), which are used in this post. % etcdctl help COMMANDS: del Removes the specified key or range of keys [key, range_end) get Gets the key or a range of keys put Puts the given key into the store CRUD % etcdctl put key1 val1 OK % etcdctl get key1      key1 val1 % etcdctl put key1 val2 OK % etcdctl get key1      key1 val2 % etcdctl del key1      1 % etcdctl get key1 %