当前位置:网站首页>[cloud native learning notes] deploy applications through yaml files

[cloud native learning notes] deploy applications through yaml files

2022-06-24 21:18:00 The night owl of the second dimension


Preface


The front part About k8s Of yaml The configuration file , This article will try to write yaml File deployment application .


One 、 Environmental preparation

except k8s Environmental Science , You also need to prepare the application image to be deployed . have access to docker Make it , If docker The warehouse can be pulled directly , It can also be configured to pull automatically . Here, choose the official website tutorial used in the last practice to use the image jocatalin/kubernetes-bootcamp.

Pull the image locally :docker pull jocatalin/kubernetes-bootcamp:v1
View local image :docker images

Two 、 Practice process

1. start-up k8s

Still use minikube:minikube start

2. Check the basic status of the cluster

Mainly node、pod、svc、deploy etc.

kubectl get node
kubectl get pod
kubectl get svc
kubectl get deploy

3. To write yaml Content

Use here deployment+service Deploy the application .

---
 apiVersion: apps/v1
 kind: Deployment
 metadata:
   name: bootcamp-deploy
   labels: 
     app: my-bootcamp
 spec:
   selector:
     matchLabels:
       app: my-bootcamp
   replicas: 2
   template:
     metadata:
       labels:
         app: my-bootcamp
     spec:
       containers:
         - name: test-bootcamp
           image: jocatalin/kubernetes-bootcamp:v1
           ports:
             - containerPort: 8080

---
 apiVersion: v1
 kind: Service
 metadata: 
   name: hello-bootcamp
 spec:
   type: NodePort
   selector:
     app: my-bootcamp
   ports:
   - protocol: TCP
     port: 80
     targetPort: 8080
     nodePort: 30008

4. View deployment results

All States are running It means there's no problem . The conditions of this machine are as follows :

E:\k8sTest>kubectl get deploy
NAME              READY   UP-TO-DATE   AVAILABLE   AGE
bootcamp-deploy   2/2     2            2           64s

E:\k8sTest>kubectl get pod
NAME                               READY   STATUS    RESTARTS   AGE
bootcamp-deploy-6b9599f456-h6ljq   1/1     Running   0          2m8s
bootcamp-deploy-6b9599f456-w9j7q   1/1     Running   0          2m8s

E:\k8sTest>kubectl get svc
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
hello-bootcamp   NodePort    10.107.175.226   <none>        80:30008/TCP   2m10s

5. Initiate a request for interface testing

Due to the port security policy of the local environment , The high port is not enabled , Here we continue to use the method introduced before , Use k8s Built in cluster url Route forwarding to access the application :
First, open the internal agent portal of the cluster :kubectl proxy
adopt pod-name To access the application :

E:\k8sTest>curl http://localhost:8001/api/v1/namespaces/default/pods/bootcamp-deploy-6b9599f456-w9j7q/proxy/
Hello Kubernetes bootcamp! | Running on: bootcamp-deploy-6b9599f456-w9j7q | v=1

E:\k8sTest>curl http://localhost:8001/api/v1/namespaces/default/pods/bootcamp-deploy-6b9599f456-h6ljq/proxy/
Hello Kubernetes bootcamp! | Running on: bootcamp-deploy-6b9599f456-h6ljq | v=1
原网站

版权声明
本文为[The night owl of the second dimension]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211317394377.html