Method of deploying k8s in docker

Time:2021-9-7

K8s

K8s is a cluster cluster in which there are multiple namespaces, multiple pods under a namespace, and multiple containers under a pod.
This article takes you from the beginning to deploy k8s in docker.

Docker Download

Docker installation: https://docs.docker.com/docker-for-mac/install/
Using k8s in docker: https://docs.docker.com/desktop/kubernetes/
In docker settings, click two as shown in the following figure.

docker中配置k8s

K8s related commands

In this section, we will briefly introduce the relevant shell commands controlled k8s from the command line.
Get relevant namespace information

kubectl get namespace

Get the relevant pod information under default. If there is no – namespace parameter, get all the namespace information

Kebectl get pod –namespace=default

Get the shell of pod

Kubectl exec -it pod bash

Display via web API

How to intuitively display k8s cluster information in web pages.

Preferred configuration agent

Kubectl proxy

The web page opens
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login

k8s网页端显示

When prompted, you need to enter a token, enter a command, and paste the obtained token into the token.

kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | grep admin-user | awk ‘{print $1}’)

At this point, go to k8s’s web page,

请添加图片描述

Click the corresponding pods to select the namespace.

请添加图片描述

Click the three points behind the pod and click execute to enter the shell of the current pod.
At this point, click open and you will find that you can’t run the relevant commands.
Relevant yaml files need to be configured.

Yaml file format

The file format of yaml is given in this section.


apiVersion: v1
kind: Pod
metadata:
  name: pod1
  labels:
    app: web
  namespace: yournamespace
spec:
  containers:
    - name: front-end
      image: ngnix
      ports:
      - containerPort: 80
    - name: flaskapp-demo
      image: jcdemo/flaskapp
      ports:
      - containerPort: 5000

This means that two containers are created under your namespace’s pod1, one is called front end, the image is ngnix, the other is called flaskapp demo, and the image is jcdemo / flaskapp.
Another example of yaml is given


apiVersion: v1
kind: Pod
metadata:
  name: pod3
  labels:
    app: web
  namespace: yournamespace
spec:
  containers:
    - name: pod-redis
      image: docker.io/redis
      ports:
      - containerPort: 5000

This means that a container named pod redis is created under pod3 of your namespace, and the image is docker.io/redis

This is the end of this article about the method of deploying k8s in docker. For more information about deploying k8s in docker, please search the previous articles of developeppaer or continue to browse the relevant articles below. I hope you will support developeppaer in the future!