Please refer to the set up memo .
I suppose you are already familiar to Docker image.
In k8s environment, there are a few concepts we should know before starting.
“INTRODUCTION TO KUBERNETES” from AWS is a conprehensive article.
note. Architecture: https://eksworkshop.com/010_introduction/architecture/architecture_control_and_data_overview/
While creating your own k8s environment, you create and delete a lot of types of objects, such as,
and so on.
We descrive each object in code.
Once codes are generated, we can create the same object many times based on the code.
The code is written in YAML format, and we define the type of object as kind
value, like
kind: Pod
Once you delete a Pod, all containers in the Pod will be deleted.
MyNote:
namespace -> context (microk8s
service -> Ingress
In this note, I create every object from YAML file as possible.
Here is the sample
apiVersion: v1
kind: Pod
metadata:
name: nginx
labels:
app: myapp
spec:
containers:
- image: nginx
name: nginx
ports:
- containerPort: 80
The following 4 fields are required for every object (not only Pod) YAML file.
apiVersion
: The version of k8s API.kind
: The type of an object.metadata
: name, UID, or namespacespec
: Details of the object.In the example above, Pod has two medatada
, name
and labels
.
name
is a name for this object.
labels
are any key-value pairs. In the example, the key is app
and the value is myapp
.
image: nginx
defines an docker image used in the Pod. When k8s creates the Pod, it download image nginx
from Docker Hub automatically.
portst
are a list of ports to expose from the container.
containerPort
is a number of port to expose on the pod’s IP address.
Here is the details.
https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.10/#pod-v1-core
Now, create a Pod from the file!
Every object is created by kubectl create -f {file}
or kubectl apply -f {file}
.
Here is the difference between create and apply.
https://intellipaat.com/community/468/difference-between-kubectl-apply-and-kubectl-create
$ kubectl get all --all-namespaces
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 129m
$ kubectl apply -f Pod_nginx.yml
pod/nginx created
$ kubectl get all --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default pod/nginx 0/1 ContainerCreating 0 5s
NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default service/kubernetes ClusterIP 10.152.183.1 <none> 443/TCP 137m
Status ContainerCreating
will be change to Running
soon.
At this stage, we can’t access to nginx service directly.
In order to do that, we need “Service” object.
Instead, we can get a shell of the Pod by kubectl exec -it nginx -- /bin/bash
.
You can get more details about the Pod with kubectl describe {pod}
.
You can edit the Pod directly from command kubectl edit pod {pod}
.
kubectl delete pods <pod> --grace-period=0 --force