How to deploy k8s in docker

How to deploy k8s in docker

K8s

k8s is a cluster. There are multiple Namespaces in the cluster. There are multiple pods under a namespace, and there are multiple containers under a pod.
This article shows you how to deploy k8s in docker from scratch.

Docker Download

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

Configure k8s in docker

k8s related commands

In this section, we will briefly introduce the relevant shell commands for controlling k8s through 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 namespace information

Kebectl get pod --namespace=default

Get the pod shell

Kubectl exec -it pod bash

Display via web API

How to intuitively display the information of the k8s cluster on a web page.

Preferred Configuration Agent

Kubectl proxy

Open the web page at this time
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login

k8s web page display

When prompted to enter a token, enter the 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, enter the k8s web page,

Please add a description of the image

Click on the corresponding pods and select the namespace.

Please add a description of the image

Click the three dots after pod and click Execute to enter the shell of the current pod.
At this moment, if you click it, you will find that you cannot run the relevant commands.
You need to configure the relevant yaml files.

YAML file format

This section gives the file format of YAML.

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 creating two containers under pod1 of yournamespace, one named front-end with the image of ngnix, and the other named flaskapp-demo with the image of jcdemo/flaskapp.
Here is another example of YAML:

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 creating a container named pod-redis under pod3 in yournamespace, with the image docker.io/redis.

This is the end of this article about how to deploy k8s in docker. For more information about docker deploying k8s, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to use docker to deploy spring boot and connect to skywalking
  • How to package the docker image, push it to the remote server and deploy it to k8s
  • Implementation of k8s deployment of docker container
  • Docker learning notes k8s deployment method
  • Skywalking containerized deployment of docker images to build k8s from testing to availability

<<:  Detailed explanation of Vue form event data binding

>>:  Detailed tutorial on MySQL installation and configuration

Recommend

Examples of preview functions for various types of files in vue3

Table of contents Preface 1. Preview of office do...

MySQL 5.5.56 installation-free version configuration method

The configuration method of MySQL 5.5.56 free ins...

5 Ways to Clear or Delete Large File Contents in Linux

Sometimes, while working with files in the Linux ...

Nginx routing forwarding and reverse proxy location configuration implementation

Three ways to configure Nginx The first method di...

Docker+selenium method to realize automatic health reporting

This article takes the health reporting system of...

How to install docker and portainer in kali

With the emergence of docker, many services have ...

How to use fdisk to partition disk in Linux

Commonly used commands for Linux partitions: fdis...

Usage and description of HTML tag tbody

The tbody element should be used in conjunction wi...

Tutorial on installing mysql5.7.18 on mac os10.12

I searched the entire web and found all kinds of ...

Vue global filter concepts, precautions and basic usage methods

Table of contents 1. The concept of filter 1. Cus...

Vue folding display multi-line text component implementation code

Folding display multi-line text component Fold an...