Implementation of k8s deployment of docker container

Implementation of k8s deployment of docker container

Environment: (docker, k8s cluster), continue with the image of the java program started by docker last time as an example (https://www.jb51.net/article/189462.htm)

Push the created image to Docker's private repository

docker tag demo-img:latest localhost:5000/demo-img:1.0

docker push localhost:5000/demo-img:1.0 

k8s deploys the image k8s creates a namespace and secret

Create a namespace cl-test. Define the name according to your own naming convention. I use this for testing.

kubectl create namespace cl-test

After creating ns, we need to create a secret for this ns

kubectl create secret docker-registry regcred --docker-server=your registry ip:5000 --docker-username=root --docker-password=xxxx@ [email protected] -n cl-test

The console returns "secret/regcred created" to indicate successful creation.

Create a yaml file for the demo service. We put service and deployment in one yaml file.

---

apiVersion: v1
kind: Service
metadata:
 name: demo-service
 namespace: cl-test
 labels:
 app: demo-service
spec:
 type: NodePort
 ports:
 - port: 8701
 targetPort: 8701
 protocol: TCP
 name: http
 selector:
 app: demo-pod
---
apiVersion: apps/v1
kind: Deployment
metadata:
 name: demo-deployment
 namespace: cl-test
spec:
 selector:
 matchLabels:
  app: demo-pod
 replicas: 1
 template:
 metadata:
  labels:
  app: demo-pod
 spec:
  containers:
  - name: demo-container
  image: localhost:5000/demo-img:1.0 #The image name + version of the local private image library ports:
  - containerPort: 8701

start up

kubectl create -f demo.yaml

View Pods

kubectl get pod -n cl-test 

Check the pod log, which is exactly the log we displayed when Java was started before

This is the end of this article about the implementation of k8s deployment of docker containers. For more relevant k8s deployment docker content, 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
  • How to deploy k8s in docker
  • Docker learning notes k8s deployment method
  • Skywalking containerized deployment of docker images to build k8s from testing to availability

<<:  JavaScript Basics Series: Functions and Methods

>>:  Detailed explanation of non-primary key column overflow monitoring in MySQL tables

Recommend

VSCode+CMake+Clang+GCC environment construction tutorial under win10

I plan to use C/C++ to implement basic data struc...

Details of the order in which MySQL reads my.cnf

Table of contents The order in which MySQL reads ...

Usage of mysql timestamp

Preface: Timestamp fields are often used in MySQL...

Vue implements tab navigation bar and supports left and right sliding function

This article mainly introduces: using Vue to impl...

Detailed explanation of JSON.parse and JSON.stringify usage

Table of contents JSON.parse JSON.parse Syntax re...

js to achieve simple drag effect

This article shares the specific code of js to ac...

TimePicker in element disables part of the time (disabled to minutes)

The project requirements are: select date and tim...

(MariaDB) Comprehensive explanation of MySQL data types and storage mechanisms

1.1 Data Type Overview The data type is a field c...

9 Practical CSS Properties Web Front-end Developers Must Know

1. Rounded Corners Today's web designs are con...

The concrete implementation of JavaScript exclusive thinking

In the previous blog, Xiao Xiong updated the meth...

IIS7 IIS8 http automatically jumps to HTTPS (port 80 jumps to port 443)

IIS7 needs to confirm whether the "URL REWRI...

WHMCS V7.4.2 Graphical Installation Tutorial

1. Introduction WHMCS provides an all-in-one solu...