Skip to content

Commit 88537d7

Browse files
Update Sunlife_Notes
1 parent 0a16fdf commit 88537d7

File tree

1 file changed

+262
-0
lines changed

1 file changed

+262
-0
lines changed

Sunlife_Notes

Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,3 +1426,265 @@ kubectl get rs
14261426

14271427
kubectl get po -l app=nginx-app
14281428
----------------------------------------------------------------
1429+
1430+
----------------------services--------------------
1431+
An abstract way to expose an application running on a set of Pods as a network service.
1432+
1433+
With Kubernetes you don't need to modify your application to use an unfamiliar service discovery mechanism. Kubernetes gives Pods their own IP addresses and a single DNS name for a set of Pods, and can load-balance across them
1434+
1435+
CLUSTER IP
1436+
1437+
ClusterIP is the default kubernetes service. This service is created inside a cluster and can only be accessed by other pods in that cluster. So basically we use this type of service when we want to expose a service to other pods within the same cluster.
1438+
1439+
Nodeport:
1440+
NodePort opens a specific port on your node/VM and when that port gets traffic, that traffic is forwarded directly to the service.
1441+
1442+
There are a few limitations and hence its not advised to use NodePort
1443+
1444+
- only one service per port
1445+
1446+
- You can only use ports 30000-32767
1447+
1448+
1449+
1450+
LoadBalancer:
1451+
This is the standard way to expose service to the internet. All the traffic on the port is forwarded to the service. It's designed to assign an external IP to act as a load balancer for the service. There's no filtering, no routing. LoadBalancer uses cloud service
1452+
1453+
Few limitations with LoadBalancer:
1454+
1455+
- every service exposed will it's own ip address
1456+
1457+
- It gets very expensive
1458+
1459+
1460+
1461+
1. Deployment & NodePort service manifest file
1462+
1463+
1464+
1465+
Deployment YAML file:
1466+
1467+
~~~~~~~~~~~~~~~~~~~~~
1468+
1469+
# Deployment
1470+
# nginx-deploy.yaml
1471+
apiVersion: apps/v1
1472+
kind: Deployment
1473+
metadata:
1474+
name: nginx-deployment
1475+
labels:
1476+
app: nginx-app
1477+
spec:
1478+
replicas: 1
1479+
selector:
1480+
matchLabels:
1481+
app: nginx-app
1482+
template:
1483+
metadata:
1484+
labels:
1485+
app: nginx-app
1486+
spec:
1487+
containers:
1488+
- name: nginx-container
1489+
image: nginx:1.7.9
1490+
ports:
1491+
- containerPort: 80
1492+
1493+
1494+
--------------------------------------
1495+
1496+
1497+
1498+
NodePort Service YAML file:
1499+
1500+
~~~~~~~~~~~~~~~~~~~~~~~~~~
1501+
1502+
# Service
1503+
# nginx-svc-np.yaml
1504+
apiVersion: v1
1505+
kind: Service
1506+
metadata:
1507+
name: my-service
1508+
labels:
1509+
app: nginx-app
1510+
spec:
1511+
selector:
1512+
app: nginx-app
1513+
type: NodePort
1514+
ports:
1515+
- nodePort: 31111
1516+
port: 80
1517+
targetPort: 80
1518+
1519+
1520+
*******************************************************************
1521+
1522+
2. Create and Display Deployment and NodePort
1523+
1524+
1525+
1526+
kubectl create –f nginx-deploy.yaml
1527+
1528+
kubectl create -f nginx-svc.yaml
1529+
1530+
kubectl get service -l app=nginx-app
1531+
1532+
kubectl get po -o wide
1533+
1534+
kubectl describe svc my-service
1535+
1536+
1537+
1538+
*******************************************************************
1539+
1540+
3. Testing
1541+
1542+
1543+
1544+
# To get inside the pod
1545+
1546+
kubectl exec [POD-IP] -it /bin/sh
1547+
1548+
1549+
1550+
# Create test HTML page
1551+
1552+
cat <<EOF > /usr/share/nginx/html/test.html
1553+
1554+
<!DOCTYPE html>
1555+
1556+
<html>
1557+
1558+
<head>
1559+
1560+
<title>Testing..</title>
1561+
1562+
</head>
1563+
1564+
<body>
1565+
1566+
<h1 style="color:rgb(90,70,250);">Hello, NodePort Service...!</h1>
1567+
1568+
<h2>Congratulations, you passed :-) </h2>
1569+
1570+
</body>
1571+
1572+
</html>
1573+
1574+
EOF
1575+
1576+
exit
1577+
1578+
1579+
1580+
Test using Pod IP:
1581+
1582+
~~~~~~~~~~~~~~~~~~~~~~~
1583+
1584+
kubectl get po -o wide
1585+
1586+
curl http://[POD-IP]/test.html
1587+
1588+
NodePort – Accessing using Service IP
1589+
1590+
1591+
1592+
Test using Service IP:
1593+
1594+
~~~~~~~~~~~~~~~~~~~~~~~~~~~
1595+
1596+
kubectl get svc -l app=nginx-app
1597+
1598+
curl http://[cluster-ip]/test.html
1599+
1600+
1601+
1602+
Test using Node IP (external IP)
1603+
1604+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1605+
1606+
http://nodep-ip:nodePort/test.html
1607+
1608+
note: node-ip is the external ip address of a node.
1609+
1610+
1611+
1612+
1613+
1614+
*******************************************************************
1615+
1616+
4. Cleanup
1617+
1618+
1619+
1620+
kubectl delete -f nginx-deploy.yaml
1621+
1622+
kubectl delete -f nginx-svc.yaml
1623+
1624+
kubectl get deploy
1625+
1626+
kubectl get svc
1627+
1628+
kubectl get pods
1629+
1630+
1631+
1632+
*******************************************************************
1633+
1634+
1635+
1636+
1637+
1638+
LoadBalancer
1639+
1640+
1641+
1642+
# 1. YAML: Deployment & Load Balancer Service
1643+
1644+
1645+
1646+
# Deployment
1647+
# controllers/nginx-deploy.yaml
1648+
apiVersion: apps/v1
1649+
kind: Deployment
1650+
metadata:
1651+
name: nginx-deployment
1652+
labels:
1653+
app: nginx-app
1654+
spec:
1655+
replicas: 1
1656+
selector:
1657+
matchLabels:
1658+
app: nginx-app
1659+
template:
1660+
metadata:
1661+
labels:
1662+
app: nginx-app
1663+
spec:
1664+
containers:
1665+
- name: nginx-container
1666+
image: nginx:1.7.9
1667+
ports:
1668+
- containerPort: 80
1669+
1670+
1671+
------------------------------------
1672+
1673+
1674+
# Service - LoadBalancer
1675+
#lb.yaml
1676+
apiVersion: v1
1677+
kind: Service
1678+
metadata:
1679+
name: my-service
1680+
labels:
1681+
app: nginx-app
1682+
spec:
1683+
selector:
1684+
app: nginx-app
1685+
type: LoadBalancer
1686+
ports:
1687+
- nodePort: 31000
1688+
port: 80
1689+
targetPort: 80
1690+
------------------------------------------------

0 commit comments

Comments
 (0)