K8s Hands-on - 1


One can find many useful articles about basic kubectl commands and minikube. Katacoda is one of the best website, for online hands-on with k8s. Here, I just shared my experience with katacoda and on-premise minikube cluster. 

First, one need set few alias at .bashrc file. 

alias k=kubectl
alias kg=kubectl get
alias m=minikube

Minikube

By default, minikube runs with 2 CPUs and 2GB RAM. It makes the system slow. minikube needs minimum 2 CPU. With trial and error i found, 1.5 GB is sufficient to run minikube. 

minikube start --memory 1536

Now few commands


kubectl config view
kubectl cluster-info
kubectl get nodes
kubectl desscribe node

minikube ip
minikube dashboard
minikube addons enable heapster
minikube addons list
minikube service list
minikube status

Service related commands


One can use svc in place of service for kubectl command, not for minikube commands

kubectl get svc 
command lists services only from default namespace, while
minikube service list 
command list services from all namespace. 
One can add "-n kube-system" for kubectl command. 
kubectl get svc -n kube-system
One can also add "--all-namespaces" for kubectl command
kubectl get svc --all-namespaces

Virtual Box


/home folder of host OS is mounted as /hosthome folder inside VirtualBox

To login to virtual box
minikube ssh
OR 
ssh to minikube's IP address with docker/tcuser
Note: None of the above methods work at Katacoda for first scenario "Launching single Node cluster" under "Introduction to Kubernets" hands-on.

Here are comparision of IP address and various interface within virtual box and outside virtual box



IP Address Interface Interface IP Address Remarks
Outside VBox Outside VBox Inside VBox Inside VBox
172.17.0.1 docker0 docker0 172.17.0.1 Pod network
192.168.99.1 vboxnet0 eth1 192.168.99.102 Minikube IP address

eth0 10.0.2.15 Node Internal IP
127.0.0.1 lo lo 127.0.0.1 Local interface


Deployment

I found, below 3 basic images to begin with

kubectl create deployment x --image=katacoda/docker-http-server
kubectl create deployment k --image=k8s.gcr.io/echoserver:1.10

kubectl create deployment i --image=nginx

The dployment should be exposed with below commans
For http-server and nginx
kubectl expose deployment x --port=80 --type=NodePort
kubectl expose deployment i --port=80 --type=NodePort
For echo-server

kubectl expose deployment k --port=8080 --type=NodePort

The deployment can be removed with

kubectl delete svc
kubectl delete deployment

Access Service

1. 
As per katacoda, the service can be tested with curl command as below

export PORT=$(kubectl get svc first-deployment -o go-template='{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}')

echo "Accessing host01:$PORT"


curl host01:$PORT

There are alternate ways also

2.

curl $(minikube service x --url) 

3. The below command invoke browser with required URL

minikube service x

4. Using proxy

kubectl proxy

Open URL in browser
http://127.0.0.1:8001/api/v1/namespaces/default/pods/POD_NAME/proxy/ 

POD

To get details about pod in JSON format

1. 
kubectl get pods -o json

2.

kubectl proxy

Open URL in browser

http://127.0.0.1:8001/api/v1/namespaces/default/pods/ 

To login to pod

kubectl exec -it $POD_NAME bash

To get enviornment variables

kubectl exec $POD_NMAE env

To display custom columns

kubectl get pod -o=custom-columns=NODE:.spec.nodeName,NAME:.metadata.name,podIP:.status.podIP,NAMESPACE:.metadata.namespace --all-namespaces

kubectl config set-context --current --namespace="namespace name"

Dashboard

Reference file for dashboard.yaml https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
Similar file, is present at Katacoda course

0 comments:

Post a Comment