Difference between revisions of "Networking in Kubernetes"

From wikieduonline
Jump to navigation Jump to search
(Created page with "The Kubernetes networking model involves creating a '''virtual network''' across the whole cluster. This means that every pod on the cluster has a unique IP address, and can c...")
 
Line 48: Line 48:
 
*Get the IP address of one of the nginx pods, then contact that nginx pod from the busybox pod using the nginx pod's IP address:
 
*Get the IP address of one of the nginx pods, then contact that nginx pod from the busybox pod using the nginx pod's IP address:
 
<pre>kubectl exec busybox -- curl $nginx_pod_ip</pre>
 
<pre>kubectl exec busybox -- curl $nginx_pod_ip</pre>
 +
 +
 +
== See also ==
 +
* {{K8s}}

Revision as of 04:50, 3 May 2020

The Kubernetes networking model involves creating a virtual network across the whole cluster. This means that every pod on the cluster has a unique IP address, and can communicate with any other pod in the cluster, even if that other pod is running on a different node.

Kubernetes supports a variety of networking plugins that implements this model in various ways. One of the most popular and easy-to-use[1] is Flannel, although as of April 2019 do not support network policies.

  • Create a deployment with two nginx pods:
cat << EOF | kubectl create -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.15.4
        ports:
        - containerPort: 80
EOF
  • Create a busybox pod to use for testing:
cat << EOF | kubectl create -f -
apiVersion: v1
kind: Pod
metadata:
  name: busybox
spec:
  containers:
  - name: busybox
    image: radial/busyboxplus:curl
    args:
    - sleep
    - "1000"
EOF
  • Get the IP addresses of your pods:
kubectl get pods -o wide
  • Get the IP address of one of the nginx pods, then contact that nginx pod from the busybox pod using the nginx pod's IP address:
kubectl exec busybox -- curl $nginx_pod_ip


See also

  • https://linuxacademy.com/blog/linux-academy/top-ten-ways-not-to-sink-the-kubernetes-ship/?utm_source=intercom&utm_medium=email&utm_campaign=AprilNewsletter2019
  • Advertising: