kube-apiserver、etcd、kubelet and docker

Here we will try to build a cluster with minimal startup using the previously compiled source code

To run a minimum level of kubernetes, there must be at least three basic components:

  • Kubelet: the agent running on each node in the cluster, which is responsible for the core components of the container
  • Kube apiserver: a component of the kubernetes control plane that provides the only access to resource operations
  • Container runtime (docker)

We created a minik8s folder for the experiment

Copy kubectl and kubelet executable binaries into this folder, and then create a pods folder

Start kubelet to try

sudo ./kubelet --pod-manifest-path=pods --fail-swap-on=false 

Then create a HelloWorld pod

apiVersion: v1

kind: Pod

metadata:

  name: hello

spec:

  containers:

  - image: busybox

    name: hello

    command: ["echo", "hello world!"]

Kubelet process will automatically load this file and try to start the corresponding pod, but an error is reported here

This is because kubernetes’ pod will give priority to starting a {k8s. By default gcr. IO / pause: pause image of 3.2, which cannot be obtained for some reasons. We can re specify an accessible image with the — pod infra container image parameter:

sudo ./kubelet --pod-manifest-path=pods --fail-swap-on=false --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.2

To start apiserver, start an etcd service first

apiVersion: v1

kind: Pod

metadata:

  name: etcd

  namespace: kube-system

spec:

  containers:

  - name: etcd

    command:

    - etcd

    - --data-dir=/var/lib/etcd

    image: registry.aliyuncs.com/google_containers/etcd:3.4.3-0

    volumeMounts:

    - mountPath: /var/lib/etcd

      name: etcd-data

  hostNetwork: true

  volumes:

  - hostPath:

      path: /var/lib/etcd

      type: DirectoryOrCreate

    name: etcd-data

Then start apiserver

apiVersion: v1

kind: Pod

metadata:

  name: kube-apiserver

  namespace: kube-system

spec:

  containers:

  - name: kube-apiserver

    command:

    - kube-apiserver

    - --etcd-servers=http://127.0.0.1:2379

    image: cnych/kube-apiserver:v1.18.5

  hostNetwork: true

Try the kubectl command line

The reason why the pod information is not obtained here is the lack of kubeconfig configuration

Create kubeconfig yaml

apiVersion: v1

kind: Config

clusters:

- cluster:

    server: http://127.0.0.1:8080

  name: mink8s

contexts:

- context:

    cluster: mink8s

  name: mink8s

current-context: mink8s

Restart the kubelet process and add the kubeconfig parameter

sudo ./kubelet --pod-manifest-path=pods --fail-swap-on=false --pod-infra-container-image=registry.aliyuncs.com/google_containers/pause:3.2 --kubeconfig=kubeconfig.yaml

Next, try to deploy an nginx in this environment

create nginx yaml

apiVersion: v1

kind: Pod

metadata:

  name: nginx

spec:

  containers:

  - image: nginx

    name: nginx

Because there is no default service account, an error will be reported directly

Create a default service account

apiVersion: v1

kind: ServiceAccount

metadata:

  name: default

  namespace: default

Then try again and find that the token is missing

Modify the service account configuration and close the token

apiVersion: v1

kind: ServiceAccount

metadata:

  name: default

  namespace: default

automountServiceAccountToken: false

You can see here that neither nginx pod nor HelloWorld started normally

This is because there is no scheduler, and the scheduler is responsible for scheduling. Here, we directly use nodeName to fix the pod to the node and edit nginx yaml

apiVersion: v1

kind: Pod

metadata:

  name: nginx

spec:

  containers:

  - image: nginx

    name: nginx

  nodeName: ubuntu

Here is a point to note. If you apply directly, an error will be reported. You need to delete the original pod before creating it

Call curl

./kubectl get pods -owide
./kubectl logs curl
apiVersion: v1

kind: Pod

metadata:

  name: curl

spec:

  containers:

  - image: curlimages/curl

    name: curl

    command: ["curl", "172.17.0.3"]

  nodeName: ubuntu

If you don’t use docker, you can directly use binary files to start apiserver

sudo ./kube-apiserver –etcd-servers=http://127.0.0.1:2379 –service-cluster-ip-range=10.0.0.0/24

Send a Message