Kubernetes deploy applications

First, the concept

1 Under

  • K8s minimum unit of scheduling, a pod contains a set of containers, a pod not work across multiple nodes
  • pod and quite logical host, each pod has its own IP address
  • The container pod share the same IP and port space
  • By default, each container file system and other containers completely isolated

2、Deployment

  • You can do better elastic expansion, load balancing. You can achieve unattended

3、Service

  • Achieve more uniform access to the entrance of the pod

Second, practice

  kubernetes installation : https://www.cnblogs.com/fanxp/p/12076982.html

1, nginx.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deplayment
spec:
  selector:
    matchLabels:
      app: nginx
  Number #
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx    
    spec:
      containers:
      - name: nginx
        # Specify the mirror
        image: nginx:alpine
        # Specify the port exposure
        ports:
        - containerPort: 80

---

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector:
    app: nginx
  ports:
    # Service internal access port
  - port: 8080
    # Pod port
    targetPort: 80

 2, in the implementation of the master 

kubectl apply -F nginx.yaml

3. Check the operation of the pod

kubectl get pod -o wide

 Renyiyitai node in: curl 10.244.2.2 

 

 4. Check the operation of the service

kubectl get service
or
kubectl get svc

 Renyiyitai node in: curl 10.96.46.205:8080

 

 5, to see if there is load balancing service

Not enter a pod in nginx modify the index.html

kubectl exec -it nginx-deplayment-5c559d5697-2r7br sh
# Change html
we /usr/share/nginx/html/index.html

Multi-access times and found that the content has changed

6, access through the domain name service

coredns is a DNS server whenever a new service is created, kube-dns dns records will be added to the service of. The pod can be in the cluster {service_name.namespace_name: port} Access service

In any of the pod: wget -q -O - Nginx-service.default.svc.cluster.local: 8080 

 

Guess you like

Origin www.cnblogs.com/fanxp/p/12084733.html