Basic commands:

1. Create an application: Kubectl create Deployment nginx-test --image=nginx # Create a pod 2 at the same time. Kubectl get pods [-n namespace] [-a] # pods: kubectl get Pods [-n namespace] Check deployment: kubectl get Deployment [-n namespace] Kubectl get service [-n namespace] # Kubectl get service [-n namespace] # Kubectl get all -n namespace 5. Exposure services: Kubectl Expose Deployment nginx-test --port=80 [--type=NodePort] --nodePort = --nodePort = --nodePort = --nodePort = --nodePort = --nodePort = --nodePort = --nodePort = --nodePort Directly expose 6 after creating the service. Kubectl delete pod name: kubectl delete pod name [-n namespace] Kubectl delete service serviceName [-n namespace] # Delete service 8 from namespace. Delete: Deployment kubectl Delete Deployment deploymentName [-n namespace] # Delete Deployment # in the corresponding namespace named deploymentName Kubectl delete all -n namespace # delete namespace kubectl delete namespace name 9. Kubectl create Deployment application name --image= image name --dey-run=client [-o yaml > deploy.yaml] # Will not actually run, will produce a yaml file 10. Deploy your application using yamL files: Kubectl apply -f deploy. Yaml # apply # If you use a local image, you need to modify the contents of the deploy. Yaml file as follows: Myweb-image imagePullPolicy: Never # Kubectl edit service kubernetes-dashboard -n kubernetes-dashboardCopy the code

Three types of ports in the K8S cluster:

1. NodePort: port provided by the cluster for external access. 2. Port: a port used to access services (containers) in a cluster. The port is not available for external use. 3. TargetPort Specifies the port of the container. This port is usually the same as the port of the internal application deployed in the container, such as mysql 3306, nginx 80, etcCopy the code

K8S cluster exposes services in several ways:

As personal understanding simple description, feel the bosses write very detailed https://blog.csdn.net/qq_21187515/article/details/112363072 1. NodePort: Open a port on each machine in the cluster. External requests for access to this port will be forwarded to a corresponding POD 2. Can be understood as a route. When accessing the corresponding URL, the ingress will parse the URL into IP + portCopy the code

Ingress-nginx exposure service:

Take the example of exposing an Nginx service, Deploy kubectl Expose Deployment nginx --port=80 # Expose the service (create a service). This port will be used later in rule-.yaml, without specifying --type=NodePortCopy the code

Install the ingress - nginx:  wget https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.47.0/deploy/static/provider/baremetal/deploy.ya Add "hostNetwork" at line 320 to "deploy. Yaml" Select * from 'alicloud' where 'id' = '# 323'; Otherwise may install failure # registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller: version number kubectl apply - f deploy.yamlCopy the code

Ingress-nginx-rule-yaml apiVersion: networking.k8s. IO /v1 kind: ingress metadata: name: ingress metadata K8s -ingress # custom spec: rules: -host: www.sda1-hacker.com # Custom route HTTP: paths: -pathtype: Prefix path: / backend: Service: name: nginx # service name: kubectl get service Port =80, port=80, port=80, port=80, port=80 Kubectl apply -f ingress-nginx-rule. Yaml kubectl get ingress #Copy the code

# Configure the mapping 192.168.157.138 www.sda1-hacker.com in hostsCopy the code

The IP address + port number is unavailableCopy the code

Kubectl apply -f XXXXX. Yml for the new worknode configuration, use DaemonSet controller (DaemonSet controller), as well as some other controllers. Used to do such as notes of five types of controller # K8S # https://blog.csdn.net/weixin_45691464/article/details/106326605Copy the code

Reference: K8S -(7) Three ways to expose services ingress-nginx details and deployment solutions