Prometheus without persistent volume on k8s (no EBS on aws eks) - amazon-web-services

I've been trying to run a Prometheus on Kubernetes without it needing of a persistent volume. Why ? Cause I'm remotly writing the data gathered by this prometheus to an AWS Managed Prometheus and would prefer not having an EBS created with the cluster. I've tried playing with the values on chart helm like for instance doing this :
server:
persistentVolume:
## If true, alertmanager will create/use a Persistent Volume Claim
## If false, use emptyDir
##
enabled: false
and same with alertmanager and pushgateway but it still create a PVC and PV.
Could someone indicates where I could find some docs or info on my use case as I can't find it?
Or maybe explain me what I'm missing or not understanding, as I'm fairly new with k8s, helm and such.
Thanks !

Related

How do I update my EKS cluster after pushing a change to a Pod's ECR image?

I have an EKS cluster running a service. After I've pushed a change to a Pod's ECR how can I get EKS to update the deployment with a new pod? So far I can only think of deleting the pod, forcing EKS to launch a new a new. Is there a better way of achieving this? I would like to have Jenkins force the pods recreation.
I recommend CI/CD here, after building your image, your CD will deploy it and Jenkins can take that role.
If the image tag hasn't changed, you can try with kubectl rollout restart deployment deployment-name (you may need this imagePullPolicy: Always).
If the image tag changes, you can use sed to replace it and run kubectl apply.
In my humble opinion, you should use v1.Jenkins-build-number or v1.merge-request-number ..., don't use latest for the image tag.

kubectl get componentstatus Unable to connect to the server: dial tcp xx.xxx.xx.x:xxx: i/o timeout

While I'm trying to get the pods or node states, from Google Cloud Platform Cloud Shell, I'm facing this error? Can someone please help me? I can see the output of the "kubectl config view".
Posting this answer as community wiki for better visibility and the fact that the possible solution was posted in the comments:
Does this answer your question? Unable to connect to the server: dial tcp i/o time out
Adding to that:
Below command:
$ kubectl config view
is used to show the configuration stored in your ./kube/config file. The fact that you can see the output of this command doesn't mean you have correct cluster configured to use with kubectl.
From the perspective of Google Cloud Platform and Cloud Shell
There is an official documentation regarding troubleshooting issues with GKE:
Cloud.google.com: Kubernetes Engine: Docs: Troubleshooting
There could be several reasons why you are getting following error:
You are referencing wrong cluster in your ~/.kube/config file.
$ gcloud container clusters get-credentials CLUSTER_NAME --zone=ZONE - you will need to run this command to fetch the correct configuration
You can also get above command from the Kubernetes Engine page (Connect button)
You are referencing a cluster in your ~/.kube/config file that was deleted
You created Private GKE cluster
For more information you can look in the Cloud Console -> Kubernetes Engine -> CLUSTER_NAME
You can also run:
$ gcloud container clusters list - this command will show clusters and their state (status) they are in
$ gcloud container clusters describe CLUSTER_NAME --zone=ZONE - this command will show you the configuration of the cluster

Kubernetes cluster still running even after deleting

I created a Kubernetes cluster using ansible-playbook command below
ansible-playbook kubectl.yaml --extra-vars "kubernetes_api_endpoint=<Path to aws load balancer server>"
Now I have deleted the cluster using command
kubectl config delete-cluster <Name of cluster>
But still EC2 nodes are running, I tried to manually stop them but they start again automatically (expected because they are running in a cluster)
Is there any way by which I can detach the nodes from the cluster or delete the cluster in total?
Kubectl config view shows below message
apiVersion: v1
clusters: []
contexts:
- context:
cluster: ""
user: ""
name: default-context
current-context: default-context
kind: Config
preferences: {}
users:
- name: cc3.k8s.local
user:
token: cc3.k8s.local
This means there is no cluster.
I want to delete the cluster in total and start fresh.
The delete-cluster command does this :
delete-cluster Delete the specified cluster from the kubeconfig
It will only delete the context from your ~/.kube/config file. Not delete the actual cluster.
You will need to write a different script for that or go into the AWS console and simply delete the nodes.
I just ran into this same problem. You need to delete the autoscaling group that spawns the worker nodes, which for some reason isn't deleted when you delete the EKS cluster.
Open the AWS console (console.aws.amazon.com), navigate to the EC2 dashboard, then scroll down the left pane to "Auto Scaling Groups". Deleting the autoscaling group should stop the worker nodes from endlessly spawning. You may also want to click on "Launch Configurations" and delete the template as well.
HTH!
As #Jason mentioned delete-cluster is not an option for you if you want to delete cluster completely.
It would be better if you put ansible playbook file content which creates cluster, then we can see how it creates cluster on AWS.
Best and easiest option for me, you can create also simple playbook file to delete cluster by changing relevant module's state to absent in playbook.
Or if it uses EKS, then you can configure your aws command line then simply run i.e aws eks delete-cluster --name devel. For more info click
If it uses Kops, then you can run kops delete cluster --name <name> --yes
For more info about Kops CMD click
If you still need help, please put ansible playbook file to question by editing.

kubernetes: using Petset in bare metal environment

I was trying to setup Cassandra cluster by kubernetes 1.3.4 new alpha feature - Petset. Following the yaml file posted here:
http://blog.kubernetes.io/2016/07/thousand-instances-of-cassandra-using-kubernetes-pet-set.html
My kubernetes cluster is based on 1.3.4 on bare metal environment with 10 powerful physical machines. However, after I created the Petset, I can get nothing from kubectl get pv.
run kubectl get pvc, i get following:
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
cass-volume-cassandra-0 Pending 4h
cass-volume-cassandra-1 Pending 4h
cass-volume-cassandra-2 Pending 4h
Reading the README here: https://github.com/kubernetes/kubernetes/blob/b829d4d4ef68e64b9b7ae42b46877ee75bb2bfd9/examples/experimental/persistent-volume-provisioning/README.md
saying the persistent volume will be automatically created if the kubenetes is running on asw, gce or Cinder. Wondering any way I can create such persistent volume and pvc on bare metal environment?
Another question: as long as I run kubernetes cluster on a few EC2 machines in aws, above persistent volume from aws EBS will be automatically created with these clauses in yaml file? or I have to allocate EBS first?
volumeClaimTemplates:
- metadata:
name: cassandra-data
annotations:
volume.alpha.kubernetes.io/storage-class: anything
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 380Gi
petset using Dynamic volume provisioning, this means volumeClaimTemplates in the petset definition request for storage from kubernetes, if storage available pvc bound and pod(petset) is running! but for now kubernetes only support "Dynamic volume provisioning" in cloud provider like gce or aws.
if you use kubernetes in bare metal cluster, other way is using network storage like ceph or gluster that need setup network storage in your cluster.
if you want using bare metal hard disk, existen solution is using hostPath type of persistent volume.
By default, the host path provisioner is set to false in the cluster/local-up-cluster.sh. You can enable it by running ENABLE_HOSTPATH_PROVISIONER=true cluster/local-up-cluster.sh. This enables the provisioner and the PV gets created.

How to setup Kubernetes Master HA on AWS

What I am trying to do:
I have setup kubernete cluster using documentation available on Kubernetes website (http_kubernetes.io/v1.1/docs/getting-started-guides/aws.html). Using kube-up.sh, i was able to bring kubernete cluster up with 1 master and 3 minions (as highlighted in blue rectangle in the diagram below). From the documentation as far as i know we can add minions as and when required, So from my point of view k8s master instance is single point of failure when it comes to high availability.
Kubernetes Master HA on AWS
So I am trying to setup HA k8s master layer with the three master nodes as shown above in the diagram. For accomplishing this I am following kubernetes high availability cluster guide, http_kubernetes.io/v1.1/docs/admin/high-availability.html#establishing-a-redundant-reliable-data-storage-layer
What I have done:
Setup k8s cluster using kube-up.sh and provider aws (master1 and minion1, minion2, and minion3)
Setup two fresh master instance’s (master2 and master3)
I then started configuring etcd cluster on master1, master 2 and master 3 by following below mentioned link:
http_kubernetes.io/v1.1/docs/admin/high-availability.html#establishing-a-redundant-reliable-data-storage-layer
So in short i have copied etcd.yaml from the kubernetes website (http_kubernetes.io/v1.1/docs/admin/high-availability/etcd.yaml) and updated Node_IP, Node_Name and Discovery Token on all the three nodes as shown below.
NODE_NAME NODE_IP DISCOVERY_TOKEN
Master1
172.20.3.150 https_discovery.etcd.io/5d84f4e97f6e47b07bf81be243805bed
Master2
172.20.3.200 https_discovery.etcd.io/5d84f4e97f6e47b07bf81be243805bed
Master3
172.20.3.250 https_discovery.etcd.io/5d84f4e97f6e47b07bf81be243805bed
And on running etcdctl member list on all the three nodes, I am getting:
$ docker exec <container-id> etcdctl member list
ce2a822cea30bfca: name=default peerURLs=http_localhost:2380,http_localhost:7001 clientURLs=http_127.0.0.1:4001
As per documentation we need to keep etcd.yaml in /etc/kubernete/manifest, this directory already contains etcd.manifest and etcd-event.manifest files. For testing I modified etcd.manifest file with etcd parameters.
After making above changes I forcefully terminated docker container, container was existing after few seconds and I was getting below mentioned error on running kubectl get nodes:
error: couldn't read version from server: Get httplocalhost:8080/api: dial tcp 127.0.0.1:8080: connection refused
So please kindly suggest how can I setup k8s master highly available setup on AWS.
To configure an HA master, you should follow the High Availability Kubernetes Cluster document, in particular making sure you have replicated storage across failure domains and a load balancer in front of your replicated apiservers.
Setting up HA controllers for kubernetes is not trivial and I can't provide all the details here but I'll outline what was successful for me.
Use kube-aws to set up a single-controller cluster: https://coreos.com/kubernetes/docs/latest/kubernetes-on-aws.html. This will create CloudFormation stack templates and cloud-config templates that you can use as a starting point.
Go the AWS CloudFormation Management Console, click the "Template" tab and copy out the complete stack configuration. Alternatively, use $ kube-aws up --export to generate the cloudformation stack file.
User the userdata cloud-config templates generated by kube-aws and replace the variables with actual values. This guide will help you determine what those values should be: https://coreos.com/kubernetes/docs/latest/getting-started.html. In my case I ended up with four cloud-configs:
cloud-config-controller-0
cloud-config-controller-1
cloud-config-controller-2
cloud-config-worker
Validate your new cloud-configs here: https://coreos.com/validate/
Insert your cloud-configs into the CloudFormation stack config. First compress and encode your cloud config:
$ gzip -k cloud-config-controller-0
$ cat cloud-config-controller-0.gz | base64 > cloud-config-controller-0.enc
Now copy the content into your encoded cloud-config into the CloudFormation config. Look for the UserData key for the appropriate InstanceController. (I added additional InstanceController objects for the additional controllers.)
Update the stack at the AWS CloudFormation Management Console using your newly created CloudFormation config.
You will also need to generate TLS asssets: https://coreos.com/kubernetes/docs/latest/openssl.html. These assets will have to be compressed and encoded (same gzip and base64 as above), then inserted into your userdata cloud-configs.
When debugging on the server, journalctl is your friend:
$ journalctl -u oem-cloudinit # to debug problems with your cloud-config
$ journalctl -u etcd2
$ journalctl -u kubelet
Hope that helps.
There is also kops project
From the project README:
Operate HA Kubernetes the Kubernetes Way
also:
We like to think of it as kubectl for clusters
Download the latest release, e.g.:
cd ~/opt
wget https://github.com/kubernetes/kops/releases/download/v1.4.1/kops-linux-amd64
mv kops-linux-amd64 kops
chmod +x kops
ln -s ~/opt/kops ~/bin/kops
See kops usage, especially:
kops create cluster
kops update cluster
Assuming you already have s3://my-kops bucket and kops.example.com hosted zone.
Create configuration:
kops create cluster --state=s3://my-kops --cloud=aws \
--name=kops.example.com \
--dns-zone=kops.example.com \
--ssh-public-key=~/.ssh/my_rsa.pub \
--master-size=t2.medium \
--master-zones=eu-west-1a,eu-west-1b,eu-west-1c \
--network-cidr=10.0.0.0/22 \
--node-count=3 \
--node-size=t2.micro \
--zones=eu-west-1a,eu-west-1b,eu-west-1c
Edit configuration:
kops edit cluster --state=s3://my-kops
Export terraform scripts:
kops update cluster --state=s3://my-kops --name=kops.example.com --target=terraform
Apply changes directly:
kops update cluster --state=s3://my-kops --name=kops.example.com --yes
List cluster:
kops get cluster --state s3://my-kops
Delete cluster:
kops delete cluster --state s3://my-kops --name=kops.identityservice.co.uk --yes