一、创建资源文件
### --- 创建namespace

[root@k8s-master01 NodeJS]# kubectl create namespace nodejs-test
namespace/nodejs-test created
二、创建secrets
### --- 创建secretsyaml文件

[root@k8s-master01 NodeJS]# kubectl edit secrets registrykey -n nodejs-test
# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: v1
data:
  .dockerconfigjson: eyJhdXRocyI6eyJyZWdpc3RyeS5jbi1iZWlqaW5nLmFsaXl1bmNzLmNvbSI6eyJ1c2VybmFtZSI6InlhbnFpX3ZpcCIsInBhc3N3b3JkIjoid3d3MzM0MjE1ZXkiLCJlbWFpbCI6InlhbnFpX3ZpcEB5ZWFoLm5ldCIsImF1dGgiOiJlV0Z1Y1dsZmRtbHdPbmQzZHpNek5ESXhOV1Y1In19fQ==
kind: Secret
metadata:
  creationTimestamp: "2021-06-23T06:17:49Z"
  name: registrykey
  namespace: nodejs-test
  resourceVersion: "699996"
  uid: 71ece7ff-506f-4609-8536-e4e83e24d2d1
type: kubernetes.io/dockerconfigjson
### --- 查看创建的secrets

[root@k8s-master01 NodeJS]#  kubectl get secrets -n nodejs-test
NAME                  TYPE                                  DATA   AGE
registrykey           kubernetes.io/dockerconfigjson        1      22s
三、创建NodeJS的service
### --- 查看service.yaml文件

[root@k8s-master01 NodeJS]# kubectl edit svc nodejs-demo -n nodejs-test
apiVersion: v1
kind: Service
metadata:
  creationTimestamp: "2021-06-23T06:24:07Z"
  labels:
    app: nodejs-demo
  name: nodejs-demo
  namespace: nodejs-test
  resourceVersion: "700674"
  uid: 622f0415-229e-46fd-80ba-7dd67ac8d53b
spec:
  clusterIP: 10.96.252.51
  clusterIPs:
  - 10.96.252.51
  ports:
  - name: container-1-web-1
    port: 3000
    protocol: TCP
    targetPort: 3000
  selector:
    app: nodejs-demo
  sessionAffinity: None
  type: ClusterIP
### --- 查看创建的service

[root@k8s-master01 NodeJS]# kubectl get svc -n nodejs-test -owide
NAME          TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)    AGE   SELECTOR
nodejs-demo   ClusterIP   10.96.252.51   <none>        3000/TCP   86m   app=nodejs-demo
四、创建NodeJS应用的endpoint
### --- 查看NodeJS应用的endpoint.yaml文件

[root@k8s-master01 NodeJS]# kubectl edit endpoints nodejs-demo -n nodejs-test
apiVersion: v1
kind: Endpoints
metadata:
  creationTimestamp: "2021-06-23T06:24:07Z"
  labels:
    app: nodejs-demo
  name: nodejs-demo
  namespace: nodejs-test
  resourceVersion: "709218"
  uid: 51210431-eaaa-44f2-8ea9-a2d9be6fd68c
subsets:
- addresses:
  - ip: 172.27.14.198
    nodeName: k8s-node02
    targetRef:
      kind: Pod
      name: nodejs-demo-7c8578b4d4-bt2dp
      namespace: nodejs-test
      resourceVersion: "709205"
      uid: 534d86bd-c0f4-4ba1-9313-9877e501c020
  ports:
  - name: container-1-web-1
    port: 3000
    protocol: TCP
### --- 查看创建的endpoint

[root@k8s-master01 NodeJS]# kubectl get endpoints -n nodejs-test -owide
NAME          ENDPOINTS            AGE
nodejs-demo   172.27.14.198:3000   89m
五、创建NodeJS应用的ingress
### --- 创建NodeJS应用ingress.yaml文件

[root@k8s-master01 NodeJS]# kubectl edit ingress nodejs-demo -n nodejs-test
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  creationTimestamp: "2021-06-23T06:24:07Z"
  generation: 1
  name: nodejs-demo
  namespace: nodejs-test
  resourceVersion: "700711"
  uid: a8d0c4d2-3f19-4c76-b419-ea933b85353a
spec:
  rules:
  - host: nodejs.test.com
    http:
      paths:
      - backend:
          service:
            name: nodejs-demo
            port:
              number: 3000
        path: /
        pathType: ImplementationSpecific
### --- 查看创建的ingress

[root@k8s-master01 NodeJS]# kubectl get ingress -n nodejs-test -owide
NAME          CLASS    HOSTS             ADDRESS         PORTS   AGE
nodejs-demo   <none>   nodejs.test.com   10.105.89.225   80      91m
六、创建NodeJS服务的deployment
### --- 创建NodeJS服务deployment.yaml文件

[root@k8s-master01 NodeJS]# kubectl edit deployment nodejs-demo -n nodejs-test
apiVersion: apps/v1
kind: Deployment
metadata:
  annotations: {}
  labels:
    app: nodejs-demo
  name: nodejs-demo
  namespace: nodejs-test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nodejs-demo
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nodejs-demo
    spec:
      affinity: {}
      containers:
      - env:
        - name: TZ
          value: Asia/Shanghai
        - name: LANG
          value: C.UTF-8
        image: registry.cn-beijing.aliyuncs.com/nodejs-demo-yanqi/nodejs-demo:20210623-153619-87148f1-master
        imagePullPolicy: IfNotPresent
        lifecycle: {}
        livenessProbe:
          failureThreshold: 2
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 1
          tcpSocket:
            port: 3000
          timeoutSeconds: 2
        name: nodejs-demo
        ports:
        - containerPort: 3000
          name: web
          protocol: TCP
        readinessProbe:
          failureThreshold: 2
          initialDelaySeconds: 30
          periodSeconds: 10
          successThreshold: 1
          tcpSocket:
            port: 3000
          timeoutSeconds: 2
        resources:
          limits:
            cpu: 428m
            memory: 1031Mi
          requests:
            cpu: 10m
            memory: 10Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /usr/share/zoneinfo/Asia/Shanghai
          name: tz-config
        - mountPath: /etc/localtime
          name: tz-config
        - mountPath: /etc/timezone
          name: timezone
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      - name: registrykey
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      tolerations:
      - effect: NoExecute
        key: node.kubernetes.io/unreachable
        operator: Exists
        tolerationSeconds: 30
      - effect: NoExecute
        key: node.kubernetes.io/not-ready
        operator: Exists
        tolerationSeconds: 30
      volumes:
      - hostPath:
          path: /usr/share/zoneinfo/Asia/Shanghai
          type: ""
        name: tz-config
      - hostPath:
          path: /etc/timezone
          type: ""
        name: timezone
### --- 查看创建的deployment.pod

[root@k8s-master01 NodeJS]# kubectl get po -n nodejs-test -owide
NAME                           READY   STATUS    RESTARTS   AGE   IP              NODE         NOMINATED NODE   READINESS GATES
nodejs-demo-7c8578b4d4-bt2dp   1/1     Running   0          21m   172.27.14.198   k8s-node02   <none>           <none>

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm’d both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

版权声明:本文为yanqi_vip原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/yanqivip/p/16086553.html