首页 > 其他分享> > |NO.Z.00398|——————————|CloudNative|——|KuberNetes&CI/CD.V36|-----------------------------------------
|NO.Z.00398|——————————|CloudNative|——|KuberNetes&CI/CD.V36|-----------------------------------------
作者:互联网
[CloudNative:KuberNetes&CI/CD.V36] [Applications.KuberNetes][|DevOps|CICD|Jenkins|Jenkins生产环境和UAT环境流水线设计|]
一、在kubernetes下创建nodejs-uat资源
### --- 创建一个nodejs-uat的namespace
[root@k8s-master01 ~]# kubectl create namespace nodejs-uat
namespace/nodejs-uat created
二、在 nodejs-uat命名空间下创建registrykey.Secret[root@k8s-master01 ~]# kubectl edit secrets registrykey -n nodejs-uat
apiVersion: v1
data:
.dockerconfigjson: eyJhdXRocyI6eyJyZWdpc3RyeS5jbi1iZWlqaW5nLmFsaXl1bmNzLmNvbSI6eyJ1c2VybmFtZSI6InlhbnFpX3ZpcCIsInBhc3N3b3JkIjoid3d3MzM0MjE1ZXkiLCJlbWFpbCI6InlhbnFpX3ZpcEB5ZWFoLm5ldCIsImF1dGgiOiJlV0Z1Y1dsZmRtbHdPbmQzZHpNek5ESXhOV1Y1In19fQ==
kind: Secret
metadata:
creationTimestamp: "2021-06-28T07:43:10Z"
name: registrykey
namespace: nodejs-uat
resourceVersion: "896630"
uid: 1d4e8b48-619b-48bf-afb0-8da9f2deb6df
type: kubernetes.io/dockerconfigjson
三、在 nodejs-uat命名空间下创建nodejs-demo.deployment[root@k8s-master01 ~]# kubectl edit deployment nodejs-demo -n nodejs-uat
apiVersion: apps/v1
kind: Deployment
metadata:
annotations: {}
labels:
app: nodejs-demo
name: nodejs-demo
namespace: nodejs-uat
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:20210627-181502-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
四、在 nodejs-uat命名空间下创建nodejs-demo.service[root@k8s-master01 ~]# kubectl edit service nodejs-demo -n nodejs-uat
apiVersion: v1
kind: Service
metadata:
creationTimestamp: "2021-06-28T07:44:11Z"
labels:
app: nodejs-demo
name: nodejs-demo
namespace: nodejs-uat
resourceVersion: "896764"
uid: 3fb492f5-ad77-44b6-9a1d-092cba416153
spec:
clusterIP: 10.111.243.47
clusterIPs:
- 10.111.243.47
ports:
- name: container-1-web-1
port: 3000
protocol: TCP
targetPort: 3000
selector:
app: nodejs-demo
sessionAffinity: None
type: ClusterIP
五、在 nodejs-uat命名空间下创建nodejs-demo.endpoints[root@k8s-master01 ~]# kubectl edit endpoints nodejs-demo -n nodejs-uat
apiVersion: v1
kind: Endpoints
metadata:
annotations:
endpoints.kubernetes.io/last-change-trigger-time: "2021-06-28T15:44:11+08:00"
creationTimestamp: "2021-06-28T07:44:12Z"
labels:
app: nodejs-demo
name: nodejs-demo
namespace: nodejs-uat
resourceVersion: "896766"
uid: a2feccea-b9c4-4355-b3c9-a9737f1e195e
subsets:
- addresses:
- ip: 172.27.14.204
nodeName: k8s-node02
targetRef:
kind: Pod
name: nodejs-demo-c88b6cb5b-w4jj4
namespace: nodejs-uat
resourceVersion: "896728"
uid: dc88af0d-3491-43e0-92a8-3a3697b22c5f
ports:
- name: container-1-web-1
port: 3000
protocol: TCP
六、在 nodejs-uat命名空间下创建nodejs-demo.ingress[root@k8s-master01 ~]# kubectl edit ingress nodejs-demo -n nodejs-uat
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
creationTimestamp: "2021-06-28T07:47:05Z"
generation: 1
name: nodejs-demo
namespace: nodejs-uat
resourceVersion: "897199"
uid: ea999c50-7be3-48bb-bcb4-e1444ad8872c
spec:
rules:
- host: uat-nodejs.test.com
http:
paths:
- backend:
service:
name: nodejs-demo
port:
number: 3000
path: /
pathType: ImplementationSpecific
七、查看创建的所有资源[root@k8s-master01 ~]# kubectl get namespace
NAME STATUS AGE
nodejs-uat Active 14m
[root@k8s-master01 ~]# kubectl get secrets -n nodejs-uat -owide
NAME TYPE DATA AGE
registrykey kubernetes.io/dockerconfigjson 1 16m
[root@k8s-master01 ~]# kubectl get po -n nodejs-uat -owide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
nodejs-demo-c88b6cb5b-w4jj4 1/1 Running 0 15m 172.27.14.204 k8s-node02 <none> <none>
[root@k8s-master01 ~]# kubectl get service -n nodejs-uat -owide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
nodejs-demo ClusterIP 10.111.243.47 <none> 3000/TCP 14m app=nodejs-demo
[root@k8s-master01 ~]# kubectl get endpoints -n nodejs-uat -owide
NAME ENDPOINTS AGE
nodejs-demo 172.27.14.204:3000 14m
[root@k8s-master01 ~]# kubectl get ingress -n nodejs-uat -owide
NAME CLASS HOSTS ADDRESS PORTS AGE
nodejs-demo <none> uat-nodejs.test.com 10.105.89.225 80 11m
八、配置本地hosts### --- 配置本地hosts
192.168.1.11 -nodejs.test.com
九、通过Chrome访问创建的资源:http://uat-nodejs.test.com/===============================END===============================
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
来自为知笔记(Wiz)
标签:kubectl,CI,name,V36,nodejs,demo,v02,uat,k8s 来源: https://www.cnblogs.com/yanqivip/p/16086584.html