Kubernetes Notes

Nodes

Create json file with the node description

{
    "apiVersion": "v1",
    "kind": "Node",
    "metadata": {
        "name": "cloud2.soho",
        "labels":{ "name": "cloud2-label"}
    },
    "spec": {
        "externalID": "cloud2.soho"
    }
}

Create the node

$ kubectl --server=http://cloud.soho:8081 create -f ./cloud2.json

List nodes

$ kubectl --server=http://cloud.soho:8081 get nodes
NAME          LABELS                              STATUS    AGE
cloud.soho    kubernetes.io/hostname=cloud.soho   Ready     43m
cloud2.soho   name=cloud2-label                   Ready     2h
cloud3.soho   name=cloud3-label                   Ready     6m

Delete node

$ kubectl --server=http://cloud.soho:8081 delete -f ./cloud2.json

Pods (minions)

Create a yaml file with the pod description

apiVersion: v1
kind: Pod
metadata:
  name: nginx-test
spec:
  containers:
  - name: nginx-test
    image: fedora/nginx
    ports:
    - containerPort: 80
$ kubectl --server=http://cloud.soho:8081 create -f test.yaml

Get Pod Info

$ kubectl --server=http://cloud.soho:8081 get pod nginx-test -o template --template={{.status.podIP}}

Delete Pod

$ kubectl --server=http://cloud.soho:8081 delete pod nginx-test

Replication Contoller

Replication controllers ensure that the correct number of pods are running even if they crash, are stopped manually or something weird happens. This are the recommended way to handle pods even if it's only one per node.

apiVersion: v1
kind: ReplicationController
metadata:
  name: webserver
spec:
  replicas: 3
  selector:
    app: web
  template:
    metadata:
      name: nginx-replicator
      labels:
        app: web
    spec:
      containers:
      - name: web-servers
        image: imcsk8/centos-nginx
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 80

References