欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Kubernetes Service

程序员文章站 2024-03-11 10:41:19
...
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp-deploy
  namespace: default
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
      release: stabel
  template:
    metadata:
      labels:
        app: myapp
        release: stabel
        env: test
    spec:
      containers:
      - name: myapp
        image: nginx:1.16.1
        imagePullPolicy: IfNotPresent
        ports:
        - name: http
          containerPort: 80
		
---
apiVersion: v1
kind: Service
metadata:
  name: myapp
  namespace: default
spec:
  type: ClusterIP
  selector:
    app: myapp
    release: stabel
  ports:
  - name: http
    port: 80
    targetPort: 80

---
apiVersion: v1
kind: Service
metadata:
  name: myapp-headless
  namespace: default
spec:
  selector:
    app: myapp
  clusterIP: "None"
  ports:
  - port: 80
    targetPort: 80
	


kubectl get pod -n kube-system

yum install build-utils -y

dig -t A myapp-headless.default.svc.cluster.local. @10.244.0.4


---
apiVersion: v1
kind: Service
metadata:
  name: myapp
  namespace: default
spec:
  type: NodePort
  selector:
    app: myapp
    release: stabel
  ports:
  - name: http
    port: 80
    targetPort: 80


[[email protected] ~]# kubectl get svc
NAME             TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)        AGE
kubernetes       ClusterIP   10.96.0.1        <none>        443/TCP        4d23h
myapp            NodePort    10.108.120.242   <none>        80:31816/TCP   5m59s
myapp-headless   ClusterIP   None             <none>        80/TCP         29m

curl 192.168.123.185:31816 
curl 192.168.123.185:31816

 

相关标签: k8s kubernetes