sh Kubernetes的Hello World Ingress

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh Kubernetes的Hello World Ingress相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env bash

: '
We'll see...
* Pod replicas
* Helm: The Kubernetes Package Manager
* Ingress resource: Exposes HTTP and HTTPS routes from outside the cluster to services within the cluster.
'

NS_HELLO=hello
NS_INGRESS=ingress

# check nodes
kubectl get nodes

# helm init
kubectl -n kube-system create serviceaccount tiller
kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller --upgrade
helm repo update

# launch ingress
kubectl create namespace $NS_INGRESS
helm install stable/nginx-ingress --name ingress --namespace $NS_INGRESS

kubectl -n $NS_INGRESS get pod,deploy,rs,svc,ep,ingress -o wide
sleep 10

# launch backend
kubectl create namespace $NS_HELLO
kubectl -n $NS_HELLO create deploy hostnames --image=nginxdemos/hello
kubectl -n $NS_HELLO scale --replicas=3 deploy hostnames
kubectl -n $NS_HELLO create service clusterip hostnames --tcp=8080:80

kubectl -n $NS_HELLO get pod,deploy,rs,svc,ep,ingress -o wide
sleep 10

# add ingress rule for backend
cat << EOF > ingress-hostnames.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: nginx
  name: hello
  namespace: $NS_HELLO
spec:
  rules:
    - host: www.example.com
      http:
        paths:
          - backend:
              serviceName: hostnames
              servicePort: 8080
            path: /hello
EOF
kubectl create -f ingress-hostnames.yaml

# cloud
EXTERNAL_IP=$(kubectl -n ingress get service/ingress-nginx-ingress-controller -o jsonpath='{.status.loadBalancer.ingress.ip}')
EXTERNAL_PORT=80
## inhouse
#EXTERNAL_IP=$(kubectl get nodes -o jsonpath='{.items[1].status.addresses[0].address}')
#EXTERNAL_PORT=$(kubectl -n ingress get service/ingress-nginx-ingress-controller -o jsonpath='{.spec.ports[0].nodePort}')

sudo -- sh -c 'echo "$EXTERNAL_IP  www.example.com" >> /etc/hosts'

curl http://www.example.com:$EXTERNAL_PORT/hostnames | grep -i "name:" | awk '{print $2}' | awk '{gsub(/<[^>]*>/,"")};1'


destroy (){
	helm delete --purge ingress && kubectl delete ns $NS_INGRESS
	kubectl -n $NS_HELLO delete deploy,svc,ingress --all && kubectl delete ns $NS_HELLO
}

以上是关于sh Kubernetes的Hello World Ingress的主要内容,如果未能解决你的问题,请参考以下文章

sh hello_world.sh

Kubernetes是啥?用它写个hello,world啊!

02.Hello那个World

打包一个Docker镜像,让你的好友加载开启一个容器,并且每隔一秒输出hello,world到指定的文件中

mac制作shell脚本示例,hello world

docker:hello world