John Mark Causing

System Administrator | Hosting Support Engineer

Bacolod City, Philippines

+639393497018

John Mark Causing

System Administrator | Hosting Support Engineer

Bacolod City, Philippines

+639393497018

Overview:

Just a short summary about containers and pods.

Pods = the smallest and most basic building block of Kubernetes model

Containers = A pod can consist of one or more containers, storage resource and a unique IP address in K8s cluster network.

Creating Pods

So this will create a pod (kind), name is “nginx” and the spec of that pod is just one container with an image of nginx web server.

cat << EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
    - name: nginx
      image: nginx
EOF

Get the backend build-in system pods using -n (name space) kube-system (-o wide to get more data like ip)

kubectl get pod -n kube-system -o wide

Get more information about a pod. Example “nginx” pod

kubectl describe pod nginx

Screenshot above shows more info about that pod like which node that pod is attached, ip, etc.

Describe a node

Get more information about a node like resources, events, etc.

kubectl describe node k8s-node1

Basic Networking.

Creating an example deployment

The commands below will create a deployment that generates two pods with the following info:

  • Create two different pods
  • Pods with nginx web server
cat << EOF | kubectl create -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.15.4
        ports:
        - containerPort: 80
EOF

The above deployment also shows 2 replicas. Which means if you delete a pod it will re-create and make sure it has always 2 replicas. See this screenshot:

Busybox-Pod

Another example of creating a pod called ‘busybox’ with an image busybox. This is just for testing our network later on.

cat << EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
  name: busybox
spec:
  containers:
  - name: busybox
    image: radial/busyboxplus:curl
    args:
    - sleep
    - "1000"
EOF

These are our pods so far. 2 nginx web server and 1 busybox.

Ping and test the network of our pods

We will test our networking using our busybox to access/contact the nginx webserver pod nginx-94f885966-wnkk4

kubectl exec busybox -- curl 192.168.169.133
This screenshot shows that busybox is able to communicate to our nginx webserver.

Troubleshooting

Screenshot above about the describe nginx pod shows there’s no IP and there’s an error. That means that something is wrong with the nodes so you have to clean up those nodes. Follow these steps:

  1. Drain the nodes. kubectl drain k8s-node1 --ignore-daemonsets and kubectl drain k8s-node2 --ignore-daemonsets
  2. Delete the nodes: kubectl delete node k8s-node1 and kubectl delete node k8s-node2
  3. Reset all nodes including master: kubeadm reset
  4. Initializes the master: kubeadm init --pod-network-cidr 192.168.0.0/16
  5. Copy the config: sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  6. Make sure all nodes are ready!

When you see this error related to the network add-on calico

  Failed to create pod sandbox: rpc error: code = Unknown desc = failed to setup network for sandbox "1f731906b74351463cfb38bf92c9473c9408bef66e182ba68fe73a92a8e1f8ce": error getting ClusterInformation: Get "https://[10.96.0.1]:443/apis/crd.projectcalico.org/v1/clusterinformations/default": x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "kubernetes")

Just re-install the network add-on calico

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml    

Screenshot below we got a successful pod with an IP address that is attached to our node2

Disk issue – pod won’t start

You see this error when you describe a pod like an nginx container won’t start:

Warning  FailedScheduling  49s (x5 over 5m5s)  default-scheduler  0/3 nodes are available: 1 node(s) had taint {node-role.kubernetes.io/master: }, that the pod didn't tolerate, 2 node(s) had taint {node.kubernetes.io/disk-pressure: }, that the pod didn't tolerate.

I’m using Windows and my linux machines are coming from multipass hyper-v so I need to stop the machines and increase the disk space using this guide

So after that, delete the pod, recreate then check the status.

Clean up!

You can delete a pod using this command

root@k8s-master:~# kubectl delete pod nginx
pod "nginx" deleted