Alibaba Cloud hosting K8S nginx-ingress opens Layer 4 ports

At present, Alibaba Cloud has just launched the K8S cluster, but the K8S cluster and a single machine are currently required to coexist to prevent various problems after the K8S is launched. Therefore, the Redis and memcache services in the cluster need to be opened. First thought of using nginx-ingress4 layer forwarding.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
  labels:
    app: redis
spec:
  selector:
    matchLabels:
      app: redis
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: redis
    spec:
      volumes:
      - name: data
        emptyDir: {}
      containers:
      - name: redis
        image: redis
        resources:
          requests:
            cpu: 250m
            memory: 512Mi
        volumeMounts:
        - mountPath: /data
          name: data
        ports:
        - containerPort: 6379
          name: redis

---

apiVersion: v1
kind: Service
metadata:
  name: redis
  labels:
    app: redis
spec:
  ports:
  - protocol: TCP
    port: 6379
    targetPort: 6379
    name: redis
  selector:
    app: redis

1. Modify the 4-layer configuration data of k8s cluster nginx-ingress
kubectl get configMap -nkube-system

kubectl edit configMap/tcp-services -nkube-system

apiVersion: v1
data:  #新增部分
  "6379": default/gearman:6379    #新增部分
kind: ConfigMap
metadata:
  name: tcp-services
  namespace: kube-system

kubectl get svc -nkube-system
can see a nginx-ingress-lb service

kubectl edit svc/nginx-ingress-lb -nkube-system

  ports:
  - name: http
    nodePort: 30270
    port: 80
    protocol: TCP
    targetPort: 80
  - name: https
    nodePort: 32333
    port: 443
    protocol: TCP
    targetPort: 443
  - name: redis                       #add by self
    nodePort: 32334               #add by self
    port: 6379                         #add by self
    protocol: TCP                   #add by self
    targetPort: 6379               #add by self
  selector:
    app: ingress-nginx
  sessionAffinity: None
  type: LoadBalancer

This time it can be accessed externally

Guess you like

Origin blog.51cto.com/fengwan/2544519