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

WeChat applet picker multi-column selector (mode = multiSelector)

Table of contents 1. Effect diagram (multiple col...

Upgrade MySQL 5.1 to 5.5.36 in CentOS

This article records the process of upgrading MyS...

Vue3 implements CSS infinite seamless scrolling effect

This article example shares the specific code of ...

6 Uncommon HTML Tags

First: <abbr> or <acronym> These two s...

Basic introductory tutorial on MySQL partition tables

Preface In a recent project, we need to save a la...

How to use geoip to restrict regions in nginx

This blog is a work note environment: nginx versi...

MySQL users and permissions and examples of how to crack the root password

MySQL Users and Privileges In MySQL, there is a d...

WeChat applet implements user login module server construction

I chose node.js to build the server. Friends who ...

Vue project realizes login and registration effect

This article example shares the specific code of ...

mysql join query (left join, right join, inner join)

1. Common connections for mysql INNER JOIN (inner...

Detailed explanation of the integer data type tinyint in MySQL

Table of contents 1.1Tinyint Type Description 1.2...

Summary of four ways to loop through an array in JS

This article compares and summarizes four ways of...

JDBC Exploration SQLException Analysis

1. Overview of SQLException When an error occurs ...